Jau*_*ume 2 html javascript jquery-mobile
我需要进行虚假window.location = "testCall"呼叫才能生成一个事件来绕过移动设备上的参数.作为本机工作,然而,我需要解除一个NotFound异常或主要解决一个假的window.location调用.可能?谢谢
Object.getOwnPropertyDescriptor(window, 'location').configurable === false
Run Code Online (Sandbox Code Playgroud)
在Chrome和Safari中(我猜在其他浏览器中).所以看起来你无法改变原生行为.
如果它表现为普通的EcmaScript 5属性并且configurable设置为true比你可以做的那样:
var descriptor = Object.getOwnPropertyDescriptor(window, 'location');
var setter = descriptor.set; // Doesn't exist although it should in spirit of ES5
descriptor.set = function (newLocation) {
try {
setter(newLocation);
} catch (e) {
console.log('Location error: ', newLocation, e);
}
};
// The line below will throw exception in real browser :(
// TypeError: Cannot redefine property: location
Object.defineProperty(window, 'location', descriptor);
Run Code Online (Sandbox Code Playgroud)
我希望浏览器供应商将他们所有的魔法属性和对象迁移到标准的EcmaScript机制,但目前我们运气不好.
| 归档时间: |
|
| 查看次数: |
1374 次 |
| 最近记录: |