-1

I'm setting a cookie with jQuery, put in a lot of days. But it always expires after just 2 hours. What can be the problem? This script is working on another site.


 $('button.close').click(function(){
     hcontent();
    setCookie( 'popupCookie', 'closed', 99999 );
  });
  
  $('button.submit').click(function(){
    $('.popup-overlay').fadeOut();
     $('#id').hide();
    setCookie( 'popupCookie', 'submited', 99999 );
  });

  function setCookie(cname, cvalue, exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
    var expires = "expires=" + d.toUTCString();
    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
  }
Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Silver
  • 21
  • 5
  • Does this answer your question? [How can I set a cookie with expire time?](https://stackoverflow.com/questions/13154552/how-can-i-set-a-cookie-with-expire-time) – Heretic Monkey Jun 23 '23 at 12:44
  • Maybe the browser thinks that the date you are providing, is a bit much in the future ...? The year you're in there is 2297 after all. – CBroe Jun 23 '23 at 12:45

1 Answers1

0

Went with the standard line and removed the above function. This one is working on every site. Not sure where the difference is.

document.cookie = "popupCookie=submited; max-age=31536000; path=/";
Silver
  • 21
  • 5