Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Catch the window.open from javascript

I have a web page into a html iframe, the web page has a javascript function to open links, that function use the window.open method to open a new window.

I cannot modify the javascript function (the page is made with mapguide), so I want to catch that call outside of the iframe to put the content of the new window into an ajax modal frame, instead of open a new window, is this possible?

like image 445
Naty Bizz Avatar asked Sep 17 '25 13:09

Naty Bizz


1 Answers

While I would not recommend this in general, you can overwrite the definition of the window.open function in the iframe, assuming your page and the iframe are in the same domain to avoid XSS security errors.

HTML:

<iframe id="myFrame" src="...">
</iframe>

javascript in the parent window:

var frame = document.getElementById('myFrame');

if (frame) {
    frame.contentWindow.open = function (url, windowName, windowFeatures) {
        // do whatever you want here (e.g. open an ajax modal frame)
    };
}
like image 175
jbabey Avatar answered Sep 20 '25 01:09

jbabey