Navigator.cookieEnabled - Web APIs 编辑
navigator.cookieEnabled
returns a Boolean value that indicates whether cookies are enabled or not. The property is read-only.
Syntax
var cookieEnabled = navigator.cookieEnabled;
cookieEnabled
is a Boolean:true
orfalse
.
navigator.cookieEnabled
is invoked inside a third-party iframe, it returns true
in Safari, Edge Spartan and IE (while trying to set a cookie in such scenario would fail). It returns false
in Firefox and Chromium-based browsers. Note: Web browsers may prevent writing certain cookies in certain scenarios. For example, Chrome 80+ does not allow creating cookies with SameSite=None
attribute, unless they are created over HTTPS and with Secure
attribute.Example
if (!navigator.cookieEnabled) {
// The browser does not support or is blocking cookies from being set.
}
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'Navigator.cookieEnabled' in that specification. | Living Standard | Initial definition |
Browser compatibility
BCD tables only load in the browser
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论