Advertisement
gitlez

YA: Simple Cookie Checking

Apr 12th, 2012
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.04 KB | None | 0 0
  1. <!-- In response to a Yahoo Answer's Question -->
  2. <html>
  3.     <head>
  4.        <title>Cookie Test</title>
  5.        <script type="text/javascript" language="Javascript">
  6.             var cookies = new Array();
  7.             function $_COOKIE(cn){
  8.                 if(!cookies.loaded){// Cookies need to be sorted and stored.
  9.                     var cs = document.cookie.split('; ');
  10.                     for( x in cs){
  11.                         var t = cs[x].split('=');
  12.                         cookies[t[0]] = t[1];
  13.                     }
  14.                     cookies.loaded = true;
  15.                 }
  16.                 return cookies[cn];
  17.             }
  18.             function checkCookie(){
  19.                 var username = $_COOKIE('username');
  20.                 if( username ){
  21.                     alert('Username: ' + username);
  22.                 }else{
  23.                     alert('Username Cookie was not located.\nTo verify:\n username=' + username);
  24.                 }
  25.             }
  26.         </script>
  27.     </head>
  28. <body onload="checkCookie();">
  29.  
  30. </body>
  31. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement