最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is it possible to open a pop up in an iframe - Stack Overflow

programmeradmin6浏览0评论

Is it possible to force a pop up to open in an iframe where the action to open the pop up has taken place?

I have a VueJs Application that displays a website inside an iframe and don't want the application to open new windows. But it is also not acceptable to just block all the popups with sand boxing, as some contain critical functionality.

Thus i am looking for any way to "force" target="_blank" onto the link on the webpage. I know that there is no standard way to do so, but would be open for any suggestion on how to alternatively solve this.

Maybe there is a way to disable the browsers ability to open new windows and hijack the calls.

Looking forward to your answers.

Is it possible to force a pop up to open in an iframe where the action to open the pop up has taken place?

I have a VueJs Application that displays a website inside an iframe and don't want the application to open new windows. But it is also not acceptable to just block all the popups with sand boxing, as some contain critical functionality.

Thus i am looking for any way to "force" target="_blank" onto the link on the webpage. I know that there is no standard way to do so, but would be open for any suggestion on how to alternatively solve this.

Maybe there is a way to disable the browsers ability to open new windows and hijack the calls.

Looking forward to your answers.

Share Improve this question edited Nov 10, 2020 at 8:43 Tobias Famos asked Nov 10, 2020 at 7:44 Tobias FamosTobias Famos 3121 gold badge3 silver badges12 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

That capability is all or nothing, mostly. Since it's a different site in the iframe, you likely don't have access to the iframe content and so can't control the links in it.

iframe has a sandbox attribute to which you could add the allow-popups option

  • allow-popups: Allows popups (such as window.open(), target="_blank", or showModalDialog()). If this keyword is not used, the popup will silently fail to open.

As in:

<iframe ... sandbox="allow-popups"></iframe>

There's also:

  • allow-popups-to-escape-sandbox: Lets the sandboxed document open new windows without those windows inheriting the sandboxing. For example, this can safely sandbox an advertisement without forcing the same restrictions upon the page the ad links to.
  • allow-modals: Lets the resource open modal windows.
发布评论

评论列表(0)

  1. 暂无评论