JavaScript Set Cookie Midnight Expiration


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

Set a cookie that expires at midnight.


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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.