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.
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 badgesError: uncaught exception: [Exception... "Illegal document.domain value" code: "1009" nsresult: "0x805303f1 (NS_ERROR_DOM_BAD_DOCUMENT_DOMAIN)" location: ""]
2 Answers
Reset to default 5According 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.