Note:For persistent cookies, we use
Fri, 31 Dec 9999 23:59:59 GMT
As the expiration date. If you do not want to use this date, you can use
The end of the world
Tue, 19 Jan 2038 03:14:07 GMT,
It is a 32-bit signed integer that can represent the maximum length of seconds starting at 1 January 1970 00:00:00 UTC (i.e.
01111111111111111111111111111111
Is
new Date(0x7fffffff * 1e3)
).
Corresponding JS operation
<script>//cookie function Addcookie (objname,objvalue,objdays) {var str = objname + "=" + Escape (ObjValue); Console.log (Infinity); Infinityconsole.log (typeof Infinity); Numberconsole.log (Infinity.constructor); function number () {[native code]}if (Objdays > 0) {var date = new Date (), var ms = Objdays*24*3600*1000;date.settime (d Ate.gettime () + ms); str + = "; Expires= "+ date.togmtstring ();} if (objdays===infinity) { str + = "; Expires=fri, DEC 9999 23:59:59 GMT ";} str + = "; path=/";d ocument.cookie = str;}; var itemtitle=document.queryselector (". Item-title"); Document.queryselector (". Sava_cookie"). AddEventListener ("click", Function (e) { var putcookieval= itemtitle.innerhtml; Addcookie (' surface ', putcookieval,infinity); }); </script>
Open website
Https://developer.mozilla.org/zh-CN/docs/Web/API/Document/cookie
JS Cookie Set maximum expiration time Infinity