Check if Cookies are enabled

Check if Cookies are enabled

How to check if cookies are enabled in a browser.
divider

How to check if cookies are enabled in a browser.

<script type="text/javascript">
var cookieEnabled=(navigator.cookieEnabled)? true : false

//if not IE4+ nor NS6+
if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled){
document.cookie="testcookie"
cookieEnabled=(document.cookie.indexOf("testcookie")!=-1)? true : false
}
if (navigator.cookieEnabled == false) {
   alert("You need to enable cookies for this site to load properly!");
}

if (cookieEnabled) { //if cookies are enabled on client's browser
//do whatever
}
</script>
Written by:  - 29 Sep, 2009