navigator.cookieEnabled returns a Boolean value that indicates whether cookies are enabled or not. The property is read-only.

句法

var cookieEnabled = navigator.cookieEnabled;
					
  • cookieEnabled 布尔 : true or false .
注意: When the browser is configured to block third-party cookies, and 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. 注意: Web browsers may prevent writing certain cookies in certain scenarios. For example, Chrome 80+ does not allow creating cookies with SameSite=None 属性, unless they are created over HTTPS and with Secure 属性。

范例

if (!navigator.cookieEnabled) {
  // The browser does not support or is blocking cookies from being set.
}
					

规范

规范 状态 注释
HTML 实时标准
The definition of 'Navigator.cookieEnabled' in that specification.
实时标准 初始定义

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
cookieEnabled Chrome 1 Edge 12 Firefox 1
1
Prior to Firefox 8, navigator.cookieEnabled would report the wrong result if a site exception was in place for the page on which the check was performed. This has been fixed.
IE Yes Opera Yes Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4
4
Prior to Firefox 8, navigator.cookieEnabled would report the wrong result if a site exception was in place for the page on which the check was performed. This has been fixed.
Opera Android Yes Safari iOS 1 Samsung Internet Android 7.0

图例

完整支持

完整支持

见实现注意事项。

元数据

  • 最后修改:
  1. Navigator
  2. 特性
    1. activeVRDisplays
    2. appCodeName
    3. appName
    4. appVersion
    5. battery
    6. buildID
    7. clipboard
    8. connection
    9. cookieEnabled
    10. credentials
    11. deviceMemory
    12. doNotTrack
    13. geolocation
    14. keyboard
    15. 语言
    16. languages
    17. locks
    18. maxTouchPoints
    19. mediaDevices
    20. mediaSession
    21. onLine
    22. oscpu
    23. permissions
    24. platform
    25. product
    26. productSub
    27. serviceWorker
    28. userAgent
    29. vendor
    30. vendorSub
    31. webdriver
    32. xr
  3. 方法
    1. canShare()
    2. getBattery()
    3. getGamepads()
    4. getUserMedia()
    5. getVRDisplays()
    6. mozIsLocallyAvailable()
    7. msLaunchUri()
    8. registerContentHandler()
    9. registerProtocolHandler()
    10. requestMediaKeySystemAccess()
    11. sendBeacon()
    12. share()
    13. taintEnabled()
    14. vibrate()
  4. HTML DOM 相关页面
    1. BeforeUnloadEvent
    2. DOMStringMap
    3. ErrorEvent
    4. GlobalEventHandlers
    5. HTMLAnchorElement
    6. HTMLAreaElement
    7. HTMLAudioElement
    8. HTMLBRElement
    9. HTMLBaseElement
    10. HTMLBaseFontElement
    11. HTMLBodyElement
    12. HTMLButtonElement
    13. HTMLCanvasElement
    14. HTMLContentElement
    15. HTMLDListElement
    16. HTMLDataElement
    17. HTMLDataListElement
    18. HTMLDialogElement
    19. HTMLDivElement
    20. HTMLDocument
    21. HTMLElement
    22. HTMLEmbedElement
    23. HTMLFieldSetElement
    24. HTMLFormControlsCollection
    25. HTMLFormElement
    26. HTMLFrameSetElement
    27. HTMLHRElement
    28. HTMLHeadElement
    29. HTMLHeadingElement
    30. HTMLHtmlElement
    31. HTMLIFrameElement
    32. HTMLImageElement
    33. HTMLInputElement
    34. HTMLIsIndexElement
    35. HTMLKeygenElement
    36. HTMLLIElement
    37. HTMLLabelElement
    38. HTMLLegendElement
    39. HTMLLinkElement
    40. HTMLMapElement
    41. HTMLMediaElement
    42. HTMLMetaElement
    43. HTMLMeterElement
    44. HTMLModElement
    45. HTMLOListElement
    46. HTMLObjectElement
    47. HTMLOptGroupElement
    48. HTMLOptionElement
    49. HTMLOptionsCollection
    50. HTMLOutputElement
    51. HTMLParagraphElement
    52. HTMLParamElement
    53. HTMLPictureElement
    54. HTMLPreElement
    55. HTMLProgressElement
    56. HTMLQuoteElement
    57. HTMLScriptElement
    58. HTMLSelectElement
    59. HTMLShadowElement
    60. HTMLSourceElement
    61. HTMLSpanElement
    62. HTMLStyleElement
    63. HTMLTableCaptionElement
    64. HTMLTableCellElement
    65. HTMLTableColElement
    66. HTMLTableDataCellElement
    67. HTMLTableElement
    68. HTMLTableHeaderCellElement
    69. HTMLTableRowElement
    70. HTMLTableSectionElement
    71. HTMLTemplateElement
    72. HTMLTextAreaElement
    73. HTMLTimeElement
    74. HTMLTitleElement
    75. HTMLTrackElement
    76. HTMLUListElement
    77. HTMLUnknownElement
    78. HTMLVideoElement
    79. HashChangeEvent
    80. 历史
    81. ImageData
    82. 定位
    83. MessageChannel
    84. MessageEvent
    85. MessagePort
    86. NavigatorGeolocation
    87. NavigatorID
    88. NavigatorLanguage
    89. NavigatorOnLine
    90. NavigatorPlugins
    91. PageTransitionEvent
    92. Plugin
    93. PluginArray
    94. PopStateEvent
    95. PortCollection
    96. PromiseRejectionEvent
    97. RadioNodeList
    98. Transferable
    99. ValidityState
    100. Window
    101. WindowBase64
    102. WindowEventHandlers
    103. WindowTimers