Thursday 31 July 2014

Checking if Cookies are Enabled in Browser

The simplest way to check for cookies is via JavaScript. The following function will return a boolean value -> true if cookies are enabled:, otherwise will return false.
<script >
function are_cookies_enabled()
  {
 var cookieEnabled = (navigator.cookieEnabled) ? true : false;

 if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled)
 { 
  document.cookie="testcookie";
  cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false;
 }
 return (cookieEnabled);
  }

 var result= are_cookies_enabled();
 alert(result);
</script>

A snippet of code using the function above was executed when you loaded this page. resutl will display true or false