Property
Name the only property that must be set, which represents the name of the cookie
expires Specifies the lifetime of the cookie, if not set, the browser turns off auto-fail
path Determines whether the cookie is available to the server for other Web pages, in general, the cookie is available for all pages in the same directory, and when the Path property is set, the cookie is only valid for all pages under the specified path and sub-path
domain Many servers consist of multiple servers, the domain property primarily sets multiple servers under the same domain to share a cookie, and if Web server a needs to share cookies with Web Server B, the domain of A's cookie needs to be property is set to B so that a cookie created by a can be shared by A and B
Secure General SSL-enabled Web sites start with HTTPS, and the secure property can set cookies to be accessed only through HTTPS or other security protocols
A cookie is essentially a string
In general, cookies cannot contain special characters such as semicolons, commas, and spaces, but they can be transmitted using encoding, which translates the private characters in the text string into corresponding hexadecimal ASCII values, using encodeURI () function converts a literal character to a valid URI using the decodeuri () function to decode
Write Cookie
var cookietest = "Name=username";d ocument.cookie= cookietest; Deposit//Semicolon split different attributes var date = Newdate ();d ate.setdate (Date.getdate () +7); Set the cookie to survive for one week document.cookie= encodeURI ("Name=user") + "; expires=" +date.toutcstring ();
Read cookies
var cookiestring= decodeuri (Document.cookie), var cookiearray= cookiestring.split (";"); for (vari=0;i< cookiearray.length;i++) { var cookienum = cookiearray[i].split ("="); var cookiename = cookienum[0]; var cookievalue = cookienum[1];}
Delete Cookies
var date = Newdate ();d ate.settime (Date.gettime () -10000);d ocument.cookie= "name=user;expires=" +date.togmtstring;// Deleting a cookie is setting its expiration time to a time value of the past