gpt4 book ai didi

javascript - 文档 cookie/出现错误 "Illegal document.domain value"

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:37:43 24 4
gpt4 key购买 nike

在使用文档 cookie 时

<script typ="text/javascript"> 
document.domain="example.com";
</script>

我有一个错误。我不知道确切的问题。

Error: uncaught exception: [Exception... "Illegal document.domain value" code: "1009" nsresult: "0x805303f1 (NS_ERROR_DOM_BAD_DOCUMENT_DOMAIN)" location: ""]

最佳答案

根据 HTML 规范,document.domain 是只读的。但是,Firefox 允许将其设置为 super 域:

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。如果您尝试设置 cookie 的域部分,设置 document.domain 与它无关。您需要提供域参数作为您分配的 cookie 字符串的一部分:

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

更多信息在这里:https://developer.mozilla.org/en/DOM/document.cookie

关于javascript - 文档 cookie/出现错误 "Illegal document.domain value",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9125186/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com