簡體   English   中英

SECURITY_ERR:在兩個站點上應用 document.domain 時出現 DOM 異常 18。 我該如何解決這個問題?

[英]SECURITY_ERR: DOM Exception 18 when applying document.domain on both sites. How do I resolve this?

我在內部服務器上有一個頁面,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。

在10.xxx服務器上,我在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.xxx 而不是實際域名有什么關系嗎?

謝謝你。

您只能使用document.domain將更具體的子域更改為更不具體的域。 像...

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

document.domain = 'mydomain.com'

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

它不能用於設置更具體的子域或完全不同的域。

您只能將document.domain設置為其當前值或當前設置的超級域。 因此,位於“foo.something.com”的頁面可以將其設置為“something.com”,但不能設置為“something.else.com”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM