How to prevent a script from changing window.location or reloading on the current page?

I want a third party script to change window.location and reload the current page using Javascript. Is there a way to track location changes or window reload events and undo them. I do not control the JavaScript library that does this, and I need to temporarily prevent page reloads during critical operations. I am not trying to prevent the user from reloading the page, just other scripts. JQuery solutions are welcome.

Thanks!

EDIT : The solution should only work in Firefox.

+4
source share
1 answer

To prevent reload() you can do something like this:

 var canReload = true; var realReload = window.reload; window.reload = function() { if (canReload) { realReload(); } } 

Basically override the reload function with your own. I am not sure that the same thing can be done with the property assignment (where window.location set). You can look at the custom functions getter / setter ( __defineSetter__ ) for Firefox and create a setter for the location window property.

+2
source

Source: https://habr.com/ru/post/1339524/


All Articles