Reading Cookies : Cookie : Development JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Development » Cookie »

 

Reading Cookies

















var cookieName = document.cookie;



This statement creates the variable cookieName and assigns it the cookie property of the document object.

The cookie property itself returns a string containing all the cookies pertaining to the current document.

Cookies are interpreted in name/value pairs.












<html>
    <body>
    <script language="JavaScript">
    <!--
       var cookies = document.cookie;
       function readCookie(name) {
          var start = cookies.indexOf(name + "=");
          if (start == -1){
              alert("Cookie not found");
          }
          start = cookies.indexOf("=", start1;
          var end = cookies.indexOf(";", start);
          if (end == -1){
              end = cookies.length;
          }
          var value = unescape(cookies.substring(start, end));
          if(value == null){
            alert("No cookie found");
          else{
            alert("Cookie value is: " + value);
          }
       }
       readCookie("navioo.com");
    -->
    </script>
    </body>
    </html>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Development
» Cookie