更改window.location原型以禁用某些重定向? [英] Change window.location prototype to disable certain redirects?

查看:347
本文介绍了更改window.location原型以禁用某些重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Greasemonkey在文档的开头有选择地禁用 window.location

I'm trying to selectively disable window.location, using Greasemonkey, at the start of the document.

我不想完全禁用javascript,只是禁用一些使用javascript完成的重定向。他们看起来像这样:

I don't want to fully disable javascript, just disable some redirects done with javascript. They look like this:

window.location = "unwanted url";


推荐答案

您无法更改 window.location prototype,因为这是 window 的本机属性,它是可配置

You can't change the window.location prototype, because this a "native property" of window and it is not configurable.

在Firefox(Greasemonkey)上,如果你试图覆盖它,那么你会得到如下错误:

On Firefox (Greasemonkey), if you try to override this then you will get errors like:


TypeError:无法重新定义非可配置属性'location'

TypeError: can't redefine non-configurable property 'location'


错误:拒绝透过本机属性的权限

Error: Permission denied to shadow native property

...取决于您的尝试方式。其他浏览器也会出现类似的错误。

...depending on how you attempt it. Other browsers give similar errors.

要阻止这种重定位,你需要在一个案例中干扰页面的javascript逐个案例。

To block this kind of relocation, you need to interfere with the page's javascript on a case-by-case basis.

请参阅停止执行Javascript功能(客户端) ())或调整以获得适用于Firefox的一般方法。虽然它可能更容易,具体取决于您的目标网页的确切代码。

See "Stop execution of Javascript function (client side) or tweak it" for a general approach that works in Firefox. Although it may be much easier, depending on your target page's exact code.

这篇关于更改window.location原型以禁用某些重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆