Detect if Cookies are enabled using JavaScript

If you are implementing cookies for your web project you need to know first that are cookies enabled or disabled by the user web browser. This can be done with the help of cookieEnabled available in window.navigator object.

On the load of the webpage we can call a javascript function that checks if cookies are enabled or not.

<!DOCTYPE html>
<title>Check if cookies are enabled or disabled</title>

<script type="text/javascript">

function checkCookiesStats() {

 if(navigator.cookieEnabled) {

   document.getElementById("check").innerHTML =
    "Cookies are enabled!!";

  else {
   document.getElementById("check").innerHTML =
    "Cookies are disabled!!";



<body onload="checkCookiesStats()">

<h2>Check Cookies stats</h2>

<p id="check"></p>