Posted By

debacelar on 07/29/10


Tagged

js cookies


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

dipser
dop3


read cookie


 / Published in: JavaScript
 

  1. // Example:
  2.  
  3. // alert( readCookie("myCookie") );
  4.  
  5. function readCookie(name)
  6.  
  7. {
  8.  
  9. var cookieValue = "";
  10.  
  11. var search = name + "=";
  12.  
  13. if(document.cookie.length > 0)
  14.  
  15. {
  16.  
  17. offset = document.cookie.indexOf(search);
  18.  
  19. if (offset != -1)
  20.  
  21. {
  22.  
  23. offset += search.length;
  24.  
  25. end = document.cookie.indexOf(";", offset);
  26.  
  27. if (end == -1) end = document.cookie.length;
  28.  
  29. cookieValue = unescape(document.cookie.substring(offset, end))
  30.  
  31. }
  32.  
  33. }
  34.  
  35. return cookieValue;
  36.  
  37. }

Report this snippet  

You need to login to post a comment.