How to block pop-up coming from iframe?

前端 未结 7 2174
独厮守ぢ
独厮守ぢ 2020-11-29 09:34

I\'m embedding page that has an exit pop-up. When you close the page, it automatically launches a pop-up window.

How to disable pop-ups coming from the ifram

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-29 09:52

    Actually, this is possible. Well at least in many cases. Often, the code in the iframe will be running something like top.window.open(...) to open a pop-up. You can redefine the window.open method so it still exists, but doesn't open a window. E.g.:

    ` window.alias_open = window.open;

    window.open = function(url, name, specs, replace) { // Do nothing, or do something smart... } `

    If you still want some pop-ups to open, you can whitelist urls within the body of window.open, and call alias_open as needed.

提交回复
热议问题