Checking Cookies With Javascript

Advertise Here

, 2005-12

How to check if the browser has cookies turned off?

Check the property “navigator.cookieEnabled”.

Sample code:

function ff() {
    if (navigator.cookieEnabled) {
        alert('Yay, cookies!');
    } else {
        alert('Bah, no cookies!');
    }
}
document.getElementById("x4265").onclick = ff;

The “navigator.cookieEnabled” is supported by all major browsers.

to see if your browser allow cookies.

Setting and Getting Cookie

To set a cookie, use “document.cookie”.

document.cookie="c1=3;c2=5";
document.cookie="c3=9";
alert("Your cookie: " + document.cookie);

to see your cookies.

blog comments powered by Disqus