如何在 Firefox 中覆盖 window.location?
我试图通过以下代码覆盖 Firefox 中的 window.location 并不断收到错误(实际上想阻止默认行为,但我认为这不相关):
Code :
window.__defineGetter__('location', function() {});
Error
redeclaration of var location
我从 以编程方式禁用window.location.reload?,但不起作用。
提前致谢, 苏尼尔
I am trying to override the window.location in Firefox, through the following code and keep getting an error (actually want to prevent the default behavior, but I think that's not relevant) :
Code :
window.__defineGetter__('location', function() {});
Error
redeclaration of var location
I started with the suggestions at Programatically disable window.location.reload?, but didn't work.
Thanks in advance,
Sunil
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
出于安全原因,Window 的
location
属性是不可配置的,因为一些破坏性的事情会在window.location.toString()
的值上进行安全检查,所以你不能这样做。The
location
property of Window is non-configurable for security reasons, because some broken things out in the wild base security checks on the value ofwindow.location.toString()
, so you can't do this.