是否可以强制在已执行打开弹出窗口操作的 iframe 中打开弹出窗口?
我有一个 VueJs 应用程序,它在 iframe 中显示一个网站,并且不希望该应用程序打开新窗口。但是,仅使用沙盒来阻止所有弹出窗口也是 Not Acceptable ,因为有些弹出窗口包含关键功能。
因此,我正在寻找任何方法将 target="_blank"
“强制”到网页上的链接上。
我知道没有标准的方法可以做到这一点,但欢迎就如何替代解决此问题提出任何建议。
也许有一种方法可以禁用浏览器打开新窗口和劫持调用的能力。
期待您的回答。
最佳答案
大多数情况下,这种能力要么全有要么全无。由于它是 iframe
中的另一个站点,您可能无法访问 iframe
内容,因此无法控制其中的链接。
iframe
有一个 sandbox
您可以向其添加 allow-popups
选项
allow-popups
: Allows popups (such aswindow.open()
,target="_blank"
, orshowModalDialog()
). If this keyword is not used, the popup will silently fail to open.
如:
<iframe ... sandbox="allow-popups"></iframe>
还有:
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.
关于javascript - 是否可以在 iframe 中打开弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64764723/