Cookie and client persistence for JavaScript client JavaScript

Source: Internet
Author: User

The Document object has a cookie attribute that allows JavaScript code to persist data on the user's hard disk,and be able to get the data stored in this way. Client persistence is an easy way to give your Web application memory.  cookies can also be used for client-side scripting and are a standard extension of the HTTP protocol.  the string of a cookie consists of a name/value (= differentiated), separated by a semicolon between different attributes.  There are 4 optional attributes of cookies 1, expires (has been replaced by max-age) survival periodexpires is an expiration date in the future, max-age in seconds to set the lifetime 2. Path Specifies the page that is associated with this cookiewith a default value, you can make other Web pages from the same network server visible by setting the path value (as long as its URLWith the specified path (the value of path), you can share this cookie (a page with access can use Docuemtn.cookie to access the specified cookie) 3. Domain for multiple Web servers sharing cookies such as domain=.example.com;path=/; so catalog.example.com orders.example.com and all the other pages on the other servers in the example.com domainhave access to this cookie Note: cannot be set to a domain other than the domain in which the server resides 4. Secure Boolean valuespecify how to transfertrue when HTTPS or other security protocols are connected before they are transmittedfalse HTTP can be transmitted Note: This 4 is a property of a cookie, not a property of a JavaScript objectnavigator.cookieenabled to see if cookies are enabled by the browser    19.2 Storage of Cookies Note: Cookie values cannot contain semicolons, commas, or whitespace characters way: name1=value1;name2=value2;max-age=seconds;path=path;domain=domain;secure;  document.getElementById ("B1"). onclick = function () {document.cookie = "version=a;max-age=2000;";var a = Document.cookie;     }With decodeURIComponent () decoding, the previous use of escape () and unescape () is now largely deprecated. With max-age settings, you can also use expires (must be the date.togmtstring () format specification) max-age=60*60*24; 1. Change the value of a cookieuse the same path and domain and the new value to set the value of the cookie once (or update the lifetime)2. Delete the value of the cookieSet Max-age value to 0, or set to any value (or empty value)  Limitations of CookiesThe total number of browsers and the size control of each cookie, typically 300 and 4KB size limits.  19.3 The reading of cookiesonly Name=value can be read, and these strings cannot be read for COOKIE4 properties. different name=value and semicolons are separated, value has multiple values, can be separated by colons, and then the custom method resolves.  Note: The unique identifier of the cookie is Path+domain19.5 Cookie Substitution methodIE UserDataFlash Sharedobject

Cookie and client persistence for JavaScript client JavaScript

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.