Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stopping window.location.replace from redirecting

Tags:

javascript

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?

like image 990
Gale Avatar asked Sep 19 '25 12:09

Gale


1 Answers

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.)

like image 155
2 revsT.J. Crowder Avatar answered Sep 21 '25 00:09

2 revsT.J. Crowder