在两个网站上应用document

在两个网站上应用document

本文介绍了SECURITY_ERR:在两个网站上应用document.domain时的DOM异常18。如何解决这个问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在内部伺服器上有一个网页,server1.mydomain.com/page.jsp,另一个网页位于不同的内部伺服器,10.xxx: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。 / p>

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

  // page.aspx on 10.xxx 
document.domain =server1.mydomain.com;
//测试是否发生同源策略违例
document.getElementById(div_el)。innerHTML = window.top.location.href;

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

  SECURITY_ERR:DOM异常18:尝试突破用户代理的安全策略



根据我的理解,当你设置document.domain时,端口号设置为null;因此,你必须在两端设置它,然后,这个错误发生了,我正在抓我的头为什么,这与我使用10.xxx而不是一个实际的域名的事实有关吗?



谢谢。

解决方案

您只能使用 document.domain 从更具体的子域更改为不太具体的域。像...

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

document.domain ='mydomain.com'

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

它不能用于设置为更特定的子域或完全不同的域。


I have a page at an internal server, server1.mydomain.com/page.jsp and another page at a different internal server, 10.x.x.x:8081/page.aspx.

On server1.mydomain.com, I set document.domain in page.jsp like this:

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

When I issue an alert on document.domain, it comes up as server1.mydomain.com.

On the 10.x.x.x server, I set document.domain in page.aspx, as a result, like this:

//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;

In Safari 5.1.5, an error pops up on the console:

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

From what I understand, when you set document.domain, the port number is set to null; so, you have to set it on both ends, which I did. Then, this error occurs and I'm scratching my head why. Does this have anything to do with the fact I'm using 10.x.x.x and not an actual domain name?

Thank you.

解决方案

You can only use document.domain to change from a more specific sub domain to a less specific domain. Like...

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

document.domain = 'mydomain.com'

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

It can't be used to set to a more specific sub domain or to an entirely different domain.

这篇关于SECURITY_ERR:在两个网站上应用document.domain时的DOM异常18。如何解决这个问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 01:52