I have an html code that I can't change but can load .js file into it.
Can I add some java script code to stop window.location.replace
from working?
To do this, you'd have to either replace the replace
function on location
, replace location
entirely, or replace window
entirely (which wouldn't be a guarantee, since you can also access it as this
at global scope in loose mode, and via a couple of other aliases).
Neither appears to be possible, not even with Object.defineProperty
.
Benjamin mentioned the history API, but I don't see anything in the history API that allows you to cancel a navigation initiated by location.replace
.
So I don't think you can do this.
(CW because this was a community effort.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With