javascript document cookie
cookie | Firefox/Netscape/NN 2 IE 3 Chrome/Safari/DOM 1 |
|
Read/Write |
Indicates the HTTP cookie associated with the domain of the document and stored on the client machine. The Netscape/Firefox browsers group all cookie data together into a single file, while IE creates a separate file for each domain's cookie data. Reading and writing the cookie property are not parallel operations. Reading a cookie property returns a semicolon-delimited list of name/value pairs in the following format: name=value |
|
Up to 20 of these pairs can be stored in the cookie property for a given domain (regardless of the number of HTML documents used in that web site). A total of 4,000 characters can be stored in the cookie, but it is advisable to keep each name/value pair to less than 2,000 characters in length. It is up to your scripting code to parse the cookie property value for an individually named cookie's value. |
|
Writing cookie property values allows more optional pairs of data associated with a single name/value pair. Cookie data must be a string, but you can deconstruct an array into a string via the Array.join( ) method for writing the cookie value, and then use String.split( ) to reconstruct the array after reading the cookie data. The format is as follows: document.cookie = "name=value [; expires=timeInGMT] [; path=pathName] [; domain=domainName] [; secure]"; |
|
No matter how many optional subproperties you set per cookie, only the name/value pair may be retrieved. All cookie data written to the cookie property is maintained in the browser's memory until the browser quits. If an expiration date has been made part of the cookie data and that time has not yet expired, the cookie data is saved to the actual cookie file; otherwise, the cookie data is discarded. The browser automatically deletes cookie data that has expired when the browser next starts. |
|
Example | |
var exp = new Date( ); var nowPlusOneWeek = exp.getTime( ) + (7 * 24 * 60 * 60 * 1000); exp.setTime(nowPlusOneWeek); document.cookie = "userName=visitor; expires=" + exp.toGMTString( ); |
|
Value | |
Cookie data as string. |
|
Default | |
None. |
<a href=https://buytopessays.com>help me write a essay</a>
top custom essay services
<a href=https://buy-eessay-online.com>my essay writer</a>
cheap custom essay
Powered by Linode.
<a href=https://brainycoursework.com>buy coursework</a>
custom coursework writing service