Javascript Cookie with no expiration date

前端 未结 9 940

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:55

    If you don't set an expiration date the cookie will expire at the end of the user's session. I recommend using the date right before unix epoch time will extend passed a 32-bit integer. To put that in the cookie you would use document.cookie = "randomCookie=true; expires=Tue, 19 Jan 2038 03:14:07 UTC;, assuming that randomCookie is the cookie you are setting and true is it's respective value.

提交回复
热议问题