Code2care : TechZone Apps & Tutorials

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>
<html>
<head>
<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!!";

  }
 
   
}

</script>

</head>


<body onload="checkCookiesStats()">

<h2>Check Cookies stats</h2>

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

</body>
</html>



Note : We do not need to prefix window to navigator.cookieEnabled.

navigator.cookieEnabled returns boolean true if cookies are enabled else false.











Top




Posts related to javascript.


1. Top 15 Programming Languages to learn 2014-2015

2. How to detect Browser and Operating System Name and Version using javaScript

3. How to make jsfiddle bootstrap ready

4. Detect if Cookies are enabled using javascript

5. How to get UTC (GMT) using javascript

6. Add Animated Scrolling to Html Page Title Script

7. Loading previous page using html button using javascript

8. Get Device Screen Width and Height using javaScript

9. Digital clock example using javaScript with Source code

    more...






Popular tags
android
x 175
eclipse
x 29
notepadplusplus
x 20
macosx
x 14
sharepoint
x 14
html
x 14
mac
x 13
androidstudio
x 11




1000+ C Programs     PHP Tutorial     JSON Tutorial     Swift Tutorial     India Pinocdes     About Us     Privacy Policy


Code2care © 2012-17