Read Cookie

[Total: 0    Average: 0/5]

This will check to see if a cookie exists or not.

Body Code:

<script>
 function CheckCookie (CookieName) {
	  var lf = "n";
    var CookieString = document.cookie;
    var CookieSet = CookieString.split (';');
    var SetSize = CookieSet.length;
    var CookiePieces
    var ReturnValue = "";
    var x = 0;
    for (x = 0; ((x < SetSize) && (ReturnValue == "")); x++) {
      CookiePieces = CookieSet[x].split ('=');
      if (CookiePieces[0].substring (0,1) == ' ') {
        CookiePieces[0] = CookiePieces[0].substring (1, CookiePieces[0].length);
      }
      if (CookiePieces[0] == CookieName) {
        ReturnValue = CookiePieces[1];
      }
     }
     if(ReturnValue=="")
         alert('A cookie was not set. '+lf+'Please ensure that your browser is accepting cookies.');
 }
   </SCRIPT>
this only checks to see if a cookie exists. (it does not write the cookie).
<a href="javascript:CheckCookie('BestCookieSP')">Click to check cookie</a>

Times Viewed: 9

Leave a Reply

Your email address will not be published. Required fields are marked *