Jump to content

detecting a Cookie in HTML

- - - - -

  • Please log in to reply
No replies to this topic

#1
code2learn

code2learn

    Newbie

  • Members
  • Pip
  • 9 posts
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;

}

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

Edited by Roger, 01 January 2011 - 06:05 PM.
removed links





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users