Cookie, localStorage, sessionStorage, and cookielocalstorage for Local Storage

Source: Internet
Author: User
Tags set cookie sessionstorage

Cookie, localStorage, sessionStorage, and cookielocalstorage for Local Storage
1. Local Storage is divided into cookies, and the newly added localStorage and sessionStorage1 and cookies are stored locally, with a maximum capacity of 4 k. They are carried during http requests of the same source, consuming bandwidth, and setting access paths, only this path and its sub-paths can access this cookie, which is valid before the set expiration time.

A. Set cookie in jquery. Expires expiration time

$. Cookie ("mycookie", "OK", {expires: 7, path :"/"});

B. Obtain the cookie using jquery.

$. Cookie ("mycookie ");

2. localStorage is stored locally and has a capacity of 5 MB or larger. It is not transmitted during request. It is shared in all same-source windows and the data remains valid until it is manually deleted and can be used as long-term data.

Settings:

LocalStorage. setItem ("data", "456"); or localStorage. data = "456 ";

Obtain:

LocalStorage. getItem ("data"); or localStorage. data

Delete:

LocalStorage. removeItem ("data ")

3. sessionStorage is stored locally and has a capacity of 5 MB or larger. It will not be carried during requests and will be valid before the current window of the same source is closed, however, sessionStorage still exists after you refresh the page or use the forward or backward buttons.

LocalStorage and sessionStorage are collectively referred to as WebStorage. WebStorage supports the event notification mechanism, which can notify the listener of data updates and make WebStorage APIs easier to use.

Note: No-trace browsing of iPhone does not support WebStorage. Only cookies can be used.

 

Related Article

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.