带有`target =" _blank"`的沙盒iFrame无法打开新选项卡或窗口 [英] Sandboxed iFrame with `target="_blank"` doesn't open new tab or window

查看:403
本文介绍了带有`target =" _blank"`的沙盒iFrame无法打开新选项卡或窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚使用 sandbox 属性创建了一个iFrame。每当我尝试打开一个链接 target =_ blank target =_ top或当我尝试使用 window.open()没有任何反应。

I just created an iFrame with the sandbox attribute. Whenever I try to open a link with target="_blank" or target="_top" or when I try to use window.open() nothing happens.

这是我的代码:

<iframe src="http://www.google.com/"
  sandbox="allow-top-navigation allow-same-origin allow-forms allow-scripts">

    Apparently your browser doesn't support iFrames!

</iframe>


推荐答案

显然,Chrome允许使用名为<$ c的未记录的沙箱属性要设置$ c> allow-popups 。该属性在Firefox中也受支持,并且是 W3C

Apparently Chrome allows an undocumented sandbox property called allow-popups to be set. The property is also supported in Firefox and is a Candidate Recommendation on W3C.

allow-popups 让沙盒框架在新窗口或标签中打开链接并且,看起来,当框架尝试打开 target =_ top的链接时,浏览器将在新选项卡或窗口中打开URL。

allow-popups lets the sandboxed frame open links in new windows or tabs and, it appears, when the frame tries to open a link with target="_top" the browser will open the URL in a new tab or window.

这篇关于带有`target =&quot; _blank&quot;`的沙盒iFrame无法打开新选项卡或窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆