Posted By

debacelar on 07/30/10


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

Onfire60
NyX


write cookie


 / Published in: Other
 

  1. // Example:
  2.  
  3. // writeCookie("myCookie", "my name", 24);
  4.  
  5. // Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.
  6.  
  7. function writeCookie(name, value, hours)
  8.  
  9. {
  10.  
  11. var expire = "";
  12.  
  13. if(hours != null)
  14.  
  15. {
  16.  
  17. expire = new Date((new Date()).getTime() + hours * 3600000);
  18.  
  19. expire = "; expires=" + expire.toGMTString();
  20.  
  21. }
  22.  
  23. document.cookie = name + "=" + escape(value) + expire;
  24.  
  25. }

Report this snippet  

You need to login to post a comment.