Iframe页面的URL更改会影响父窗口的URL,阻止了一个源帧。

7
我使用这段代码。
<script>
  <!-- Hide Script
    if (top.location != self.location) {
     top.location = self.location
    }
  //End Hide Script -->
</script>

然而最近我在chrome控制台中遇到了这样的错误,代码停止工作了。

(index):15 不安全的JavaScript尝试启动导航。它来自源自 'http://preview.themeforest.net' 帧,目标为 'http://site.test' 的帧。 该帧企图将导航指向其顶级窗口,但是既不与其目标同源,也未接收到用户手势。 请参阅https://www.chromestatus.com/features/5851021045661696

(index):21 无法执行'Location'上的'replace':当前窗口没有权限将目标框架导航至'http://site.test''。

在Firefox和Opera中,该代码可以正常工作,在Chrome中却不行。

如何修复这些错误?

有点像这个问题

1个回答

7

我能通过JS将它添加到site.test的子iframe沙盒中吗?以下是iframe代码:<iframe class="full-screen-preview__frame" src="site.test " name="preview-frame" frameborder="0" noresize="noresize" data-view="fullScreenPreview"> </iframe> - Виктор Лернер

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接