12/4/10

Detecting a Cookie

Here is a piece of code that can help people detect cookies. Cookies play an important part in the website.

*****************#####*****************
JS Code:
window.onload = showCookies;

function showCookies() {
    var outMsg = "";

    if (document.cookie == "") {
        outMsg = "There are no cookies here";
    }
    else {
        var thisCookie = document.cookie.split("; ");
        for (var i=0; i<thisCookie.length; i++) {
            outMsg += "Cookie name is '" + thisCookie[i].split("=")[0];
            outMsg += "', and the value is '" + thisCookie[i].split("=")[1] + "'<br />";
        }
    }
    document.getElementById("ELEMENT ID").innerHTML = outMsg;
}

*****************#####*****************


SHARE THIS POST: