Navigator:cookieEnabled 属性

Baseline 2024
Newly available

Since September 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

navigator.cookieEnabled 返回返回一个布尔值,指示是否启用了 cookie。

该属性是只读的。

一个布尔值。

备注: 当浏览器配置为阻止第三方的 cookie 时,如果在第三方 iframe 中调用 navigator.cookieEnabled,它会在 Safari、Edge Spartan 和 IE 中返回 true(而在此情况下尝试设置 cookie 会失败)。在 Firefox 和基于 Chromium 的浏览器中,它会返回 false

备注: 在某些情况下,Web 浏览器可能会阻止写入某些 cookie。例如,基于 Chrome 的浏览器以及一些实验版本的 Firefox 不允许创建具有 SameSite=None 属性的 cookie,除非它们通过 HTTPS 创建并具有 Secure 属性。

示例

js
if (!navigator.cookieEnabled) {
  // 浏览器不支持或阻止设置 cookie。
}

规范

Specification
HTML
# dom-navigator-cookieenabled-dev

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
cookieEnabled

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
See implementation notes.
Has more compatibility info.