带沙盒iframe的<a target="_top"/>和window.open“”,“ _top”有什么区别?

问题描述

我有一台iframe,其中有一个链接一个按钮。父窗口和iframe的域不同。

我的用例是,在单击这两个小部件时,我需要将用户导航到父窗口上的其他URL。

我的锚标记看起来像这样-

<a href="http://example.com" target="_top">Click Me!</a>

在我的按钮上,单击“我正在做window.open,像这样-

window.open("http://example.com","_top");

我的锚标记单击正常,并更改了父窗口的URL。

但是单击按钮不起作用,并且出现以下错误

Unsafe JavaScript attempt to initiate navigation for frame with origin '...' from frame with URL '...'. The frame attempting navigation of the top-level window is sandBoxed,but the flag of 'allow-top-navigation' or 'allow-top-navigation-by-user-activation' is not set.

我的问题

  • 两个人的行为不一样吗?
  • 如果我们在iframe上设置“ sandBox属性,但不提供“ allow-top-navigation”和“ allow-top-navigation-by-user-activation”标志,那么定位标记href是如何能够在父窗口上打开链接
  • 此外,即使未设置allow-top-navigation标志,也可以通过单击按钮来触发父窗口上的导航吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)