Catch the window.open from javascript

前端 未结 3 474
自闭症患者
自闭症患者 2021-01-21 15:05

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 modif

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-21 15:31

    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:

    
    

    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)
        };
    }
    

提交回复
热议问题