javascript - 是否可以在 iframe 中打开弹出窗口

标签 javascript html css vue.js

是否可以强制在已执行打开弹出窗口操作的 iframe 中打开弹出窗口?

我有一个 VueJs 应用程序,它在 iframe 中显示一个网站,并且不希望该应用程序打开新窗口。但是,仅使用沙盒来阻止所有弹出窗口也是 Not Acceptable ,因为有些弹出窗口包含关键功能。

因此,我正在寻找任何方法将 target="_blank"“强制”到网页上的链接上。 我知道没有标准的方法可以做到这一点,但欢迎就如何替代解决此问题提出任何建议。

也许有一种方法可以禁用浏览器打开新窗口和劫持调用的能力。

期待您的回答。

最佳答案

大多数情况下,这种能力要么全有要么全无。由于它是 iframe 中的另一个站点,您可能无法访问 iframe 内容,因此无法控制其中的链接。

iframe 有一个 sandbox您可以向其添加 allow-popups 选项

的属性
  • 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.

如:

<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/

相关文章:

javascript - 如何使用 javascript 读取此 JSON 并获取值?

Javascript 用数组填充选项框

html - 多个悬停替换

html - 为什么 height=100% 不起作用?

html - 防止在 div 内包装元素

javascript - 正则表达式来剪切数字

javascript - 什么是 ECMAScript Editon 5.1,它有什么用?

javascript - 使用 createDocumentFragment 替换表中的现有列

php - 在 joomla facebook 插件中设置透明背景

html - 有没有工具可以获取 css 类并使它们内联?