在iframe中的Window.top和top.document

3
我有两个页面,page1.html(我的页面)和page2.html(外部页面),page1.html使用iframe加载page2.html。 page2.html基本上包含用户信息,包括菜单和表单。它有一个带有以下代码的注销功能。
$('#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,这两者之间的主要区别是什么。

谢谢。


1
对于你问题的第二部分,请使用此链接:https://dev59.com/C3A75IYBdhLWcg3wW328 - Jose Marques
1
您不能使用JavaScript执行此功能。使用以下链接了解更多信息:https://dev59.com/Q18f5IYBdhLWcg3wD-8v - Jose Marques
4个回答

1

谢谢,我理解跨域问题,并且这个链接很好,我可以访问这两个站点,但是域名不同,我无法更改它们,所以我必须使用该文档中的第二种方法。 - Nisar Afridi

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

0

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


0

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