admin管理员组文章数量:1296885
I'm just curious if document.cookie
can ever return undefined
.
I read quirksmode's article on cookies and I looked at "Is !document.cookie reliable?" but they don't explicitly answer this question.
Can document.cookie
ever be undefined
?
I'm just curious if document.cookie
can ever return undefined
.
I read quirksmode's article on cookies and I looked at "Is !document.cookie reliable?" but they don't explicitly answer this question.
Can document.cookie
ever be undefined
?
-
Some of my code that is pulling from cookies was breaking a page on my site. So I'm writing some defensive code and wasn't sure if I needed to account for
document.cookie
being undefined. – christo8989 Commented Jun 5, 2015 at 18:53 -
1
No, it's never
undefined
in browsers that support it, and that's almost every browser in use today. It's also not an ordinary object, but a very special one, with special properties, for instance you can set it's value multiple times without overwriting it. – adeneo Commented Jun 5, 2015 at 18:54 -
that sounds like a problem with using an actual cookie that doesn't exist, not
document.cookie
itself – CrayonViolent Commented Jun 5, 2015 at 18:55 - @CrayonViolent Yes but it got me thinking about this. – christo8989 Commented Jun 5, 2015 at 18:57
- Old question, but this is kind of funny: ...No, it's never undefined in browsers that support it, and that's almost every browser in use today... - Well, if it's ALMOST all browsers, then it CAN be undefined. – Patrick Commented Jun 17, 2019 at 10:29
2 Answers
Reset to default 5The document.cookie
property is defined in DOM Level 2, and implemented in every major browser. It sets/gets a string, which may be an empty string (which is falsey, but not undefined
).
No.
You can read the spec here http://www.w3/TR/DOM-Level-2-HTML/html.html#ID-8747038
It throws an error if it's set to a value that doesn't adhere to the spec.
本文标签: javascriptIs documentcookie ever undefinedStack Overflow
版权声明:本文标题:javascript - Is document.cookie ever undefined? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741643904a2390074.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论