Web Storage---cookie,localstorage,sessionstorage

Source: Internet
Author: User
Tags sessionstorage

Pure JavaScript manipulation cookies only need to remember two points:

Remove all cookies in the Cookie:document.cookie that contain a domain name, stored in Prop1=value1;prop2=value2...propn=valuen form, So it takes two times to find an attribute to use the String.IndexOf method.

Stores cookie:document.cookie=prop=value;expires= (date) date. togmtstring (); Yes, one is the value, one is the expiry time!

Of course, it is necessary to note that the Date object in JS, see the following sentence

var d=New  Date (); Console.log (d);d. Setminutes (D.getminutes ()+60); Console.log (d);

The output is

Date {Wed Oct 11:10:30 gmt+0800} Date {Wed Oct 12:10:30 gmt+0800} Setminutes will automatically forward the bit, so you can control the expiry time in this way, you can setseconds by seconds, by Setminutes, by the hour sethours, setdate by day, setmonth by month, Year setFullYear and so on. destroying a cookie simply sets its expiry time to a past time. HTML5 provides two new ways for clients to store data:
sessionstorage: Data storage for a sessionlocalstorage: Data storage with no time limitPreviously, these were all done by cookies. However, cookies are not suitable for storing large amounts of data because they are passed by each request to the server, which makes the cookie slow and inefficient. for different sites, the data is stored in different regions, and a Web site can only access its own data. Access to it is also very simpleSessionstorage.propname&localstorage.propname, directly the name as a property of Sessionstorage and Localstorage, the corresponding value as the value of the property, you can! So easy!

Web Storage---cookie,localstorage,sessionstorage

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.