I'm trying to selectively disable window.location
, using Greasemonkey, at the start of the document.
I don't want to fully disable javascript, just disable some redirects done with javascript. They look like this:
window.location = "unwanted url";
I don't think it's possible.
window.location
(fails silently)location.__proto__ = Something.prototype
location.constructor.prototype
is basicallyObject.prototype
__definesetter__
fails silentlyObject.defineProperty
gives an error like,TypeError: Cannot redefine property: href
delete window.location
anddelete window.location.href
don't do anythingI'm out of ideas...
quite too late but you can do it simply without removing the whole script with
Object.prototype.watch
:You can't change the
window.location
prototype, because this a "native property" ofwindow
and it is not configurable.On Firefox (Greasemonkey), if you try to override this then you will get errors like:
and
...depending on how you attempt it. Other browsers give similar errors.
To block this kind of relocation, you need to interfere with the page's javascript on a case-by-case basis.
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.