Sandboxed iFrame with `target=“_blank”` doesn't open new tab or window

末鹿安然 提交于 2019-12-07 08:08:00

问题


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.

Here's my code:

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

回答1:


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



来源:https://stackoverflow.com/questions/21236616/sandboxed-iframe-with-target-blank-doesnt-open-new-tab-or-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!