How to Check if Cookies are Enabled or Disabled

javascript
Published on January 6, 2020

The navigator.cookieEnabled property can be used to check whether cookies are currently enabled or not.

Cookies can be used for tracking purposes, so some users may prefer to disable them in their browser. However if any web application is dependent on cookies, then it won't perform as expected.

So before trying to read or write cookies with Javascript, it is better to check whether cookies are enabled or not. If cookies are disabled, then the user can be informed to enable cookies in order to proceed further, or the application may follow a different logic — like not using any cookies at all.

Instead of automatically assuming that cookies must be enabled by default, and then resulting in a crash later on, it is better to do a prior check.

The navigator.cookieEnabled property can be used to check whether cookies are enabled or disabled. This returns true if cookies are enabled, or false if cookies are disabled.

if(navigator.cookieEnabled) {
	// cookies are enabled
	// read, write and delete cookies
}
else {
	// cookies are disabled, show an error message to the user, or follow other alternative
}

Live Example

Are cookies enabled ?
In this Tutorial