JavaScript Set Cookie


/ Published in: JavaScript
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.