Posted By

jonkemp on 09/04/10


Tagged

javascript


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

koyotebr
dop3


JavaScript Set Cookie


 / Published in: JavaScript
 

URL: http://www.quirksmode.org/js/cookies.html

The cookie expires the number of days from the time it is set.

  1. function createCookie(name,value,days) {
  2. if (days) {
  3. var date = new Date();
  4. date.setTime(date.getTime()+(days*24*60*60*1000));
  5. var expires = "; expires="+date.toGMTString();
  6. }
  7. else var expires = "";
  8. document.cookie = name+"="+value+expires+"; path=/";
  9. }

Report this snippet  

You need to login to post a comment.