Navigator.cookieEnabled
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
.
Note: 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.
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 |
---|
HTML Standard (HTML) # dom-navigator-cookieenabled-dev |
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
cookieEnabled |
1 |
12 |
1
Before 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. |
4
navigator.cookieEnabled returns true even if the browser is set to block cookies (for example, if the page is in the Restricted sites security zone).
|
≤12.1 |
1 |
1 |
18 |
4
Before 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. |
≤12.1 |
1 |
1.0 |
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Navigator/cookieEnabled