【发布时间】:2012-04-19 12:53:26
【问题描述】:
我在内部服务器上有一个页面 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 而不是实际域名有关吗?
谢谢。
【问题讨论】:
标签: javascript cross-domain user-agent same-origin-policy domexception