关于javascript:iframe中的javascript:Window.top和top.document

Window.top and top.document in iframe

我有2页,page1.html(mypage)和page2.html(external),page1.html正在使用iframe加载page2.html。 page2.html具有基本的用户信息,它包含菜单,表格。 有以下代码的注销功能

1
2
3
4
5
6
$('#inetLogoutId').click(function(event) {
        var logoutMsg ="Are you sure you want to log out?";
        dialogConfirm(logoutMsg, function() {
            top.document.location.href = path +"/logout";
        })
    });

由于Uncaught DOMException: Blocked a frame with origin"https://example.com" from accessing a cross-origin frame.,注销无法正常工作,如果注销功能修改为window.top.location.href,该怎么办。 这两个之间的主要区别是什么

谢谢


如果iframe的父域名位于其他域名上,则无法访问。

尽管您可以通过其他方式解决此问题:
http://madskristensen.net/post/iframe-cross-domain-javascript-calls


我们必须使用window.top.location.href = path +"/logout";


这是由于同源策略。 您已将所有文件保留在同一网站或主机上。 同源策略可防止跨源访问。