2012-02-03 61 views

回答

5

根據HTML規範,document.domain是隻讀的。不過,Firefox允許其設置爲超級域:

https://developer.mozilla.org/en/document.domain

In the DOM HTML specification, this property is listed as being read-only. However, Mozilla will let you set it to a superdomain of the current value, constrained by its base domain. For example, on developer.mozilla.org it is possible to set it to "mozilla.org" but not "mozilla.com" or "org".

你清楚地得到的錯誤說你讓一個非法域分配。

您提到您的問題的曲奇。如果您嘗試設置Cookie的域名部分,則設置document.domain與此無關。您需要提供一個域參數作爲cookie字符串的一部分,你分配:

document.cookie = "foo=bar;domain=example.com"; 

此處瞭解詳情:https://developer.mozilla.org/en/DOM/document.cookie

0

它適用於IE瀏覽器也是如此。它的起源相同,我們需要縮短域名。