SECURITY_ERR:在两个站点上应用 document.domain 时出现 DOM 异常 18。我该如何解决这个问题?

2024-01-07

我在内部服务器 server1.mydomain.com/page.jsp 上有一个页面,在不同的内部服务器上有另一个页面 10.x.x.x:8081/page.aspx。

在 server1.mydomain.com 上,我在 page.jsp 中设置 document.domain,如下所示:

//page.jsp on server1.mydomain.com
document.domain = document.domain;

当我在 document.domain 上发出警报时,它显示为 server1.mydomain.com。

在10.x.x.x服务器上,我在page.aspx中设置了document.domain,结果如下:

//page.aspx on 10.x.x.x
document.domain = "server1.mydomain.com";
// test if same-origin policy violation occurs
document.getElementById("div_el").innerHTML = window.top.location.href;

在Safari 5.1.5中,控制台弹出错误:

SECURITY_ERR: DOM Exception 18: An attempt was made to break through the security policy of the user agent."

据我了解,当您设置 document.domain 时,端口号设置为 null;所以,你必须把它设置在两端,我就是这么做的。然后,这个错误发生了,我很困惑为什么。这与我使用 10.x.x.x 而不是实际域名有什么关系吗?

谢谢。


你只能使用document.domain从更具体的子域更改为不太具体的域。喜欢...

console.log(document.domain); // server1.mydomain.com

document.domain = 'mydomain.com'

console.log(document.domain); // mydomain.com

它不能用于设置更具体的子域或完全不同的域。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

SECURITY_ERR:在两个站点上应用 document.domain 时出现 DOM 异常 18。我该如何解决这个问题? 的相关文章

随机推荐