Javascript Cookie with no expiration date

前端 未结 9 914

I would like to set up a cookie that never expires. Would that even be possible?

 document.cookie = \"name=value; expires=date; path=path;domain=domain; secu         


        
9条回答
  •  独厮守ぢ
    2020-11-27 13:57

    You can make a cookie never end by setting it to whatever date plus one more than the current year like this :

    var d = new Date();    
    document.cookie = "username=John Doe; expires=Thu, 18 Dec " + (d.getFullYear() + 1) + " 12:00:00 UTC";
    

提交回复
热议问题