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.