Posted By

jonkemp on 09/04/10


Tagged

javascript


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

heinz1959
thinkbliss


JavaScript Set Cookie Midnight Expiration


 / Published in: JavaScript
 

Set a cookie that expires at midnight.

  1. function createCookie(name,value,path) {
  2. var expires = "";
  3. var date = new Date();
  4. var midnight = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59);
  5. expires = "; expires=" + midnight.toGMTString();
  6. if (!path) {
  7. path = "/";
  8. }
  9. document.cookie = name + "=" + value + expires + "; path=" + path;
  10. }

Report this snippet  

You need to login to post a comment.