Protect window.opener from change

923 views Asked by At

There is a JavaScript code that opens new page which tries to change the mother-page with the help of window.opener. I need to Protect mother-page from any change. Any advice on how to do it?

Code like this needs to be blocked

window.opener.location.href='http://google.com/';

1

There are 1 answers

1
maestr0 On

No, you cannot stop executing "window.opener" but what you can do is assign the opener function to a different variable and mock the original one.

window.opener_old = window.opener;
window.opener = function(){};

If some other script tries to execute window.opener, the new empty function is going to be called and nothing will happen.