最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - document cookieGot an error "Illegal document.domain value" - Stack Overflow

programmeradmin1浏览0评论

while using document cookie

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

I got an error.i don't know the exact problem.

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

while using document cookie

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

I got an error.i don't know the exact problem.

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

Share Improve this question edited Feb 3, 2012 at 7:44 Ateş Göral 140k27 gold badges141 silver badges191 bronze badges asked Feb 3, 2012 at 7:34 user1186966user1186966 431 gold badge1 silver badge3 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

According to the HTML spec, document.domain is read-only. However, Firefox allows setting it to a superdomain:

https://developer.mozilla/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 it is possible to set it to "mozilla" but not "mozilla." or "org".

The error you're getting clearly states that you're making an illegal domain assignment.

You mention cookies in your question. If you're trying to set the domain part of a cookie, setting document.domain has nothing to do with it. You need to provide a domain parameter as part of the cookie string that you're assigning:

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

More info here: https://developer.mozilla/en/DOM/document.cookie

it works on IE as well. it's for same origin, we need to shorten the domain name.

发布评论

评论列表(0)

  1. 暂无评论