Html5 web local storage will replace our cookies

Source: Internet
Author: User
Tags sessionstorage

Comments: A local cache mechanism is provided for us in html5. It will replace our cookies, and it will not be sent with the browser. Our server-side html5 cache mainly includes localStorage, and sessionStorage. For details, please refer to this article. In html5, we provide a local cache mechanism, which will replace our cookies and will not send our servers with the browser. We can use js to operate the local cache freely on the client. In html5, the cache mainly includes localStorage and sessionStorage. Their usage is consistent. The difference is that they have different time limits. LocalStorage does not have a time limit. In this case, session-based data storage will be deleted after the session is closed or the website is left.

Next, let's take a look at the official example operations.:
Javascript

The Code is as follows:
LocalStorage. fresh = "vfresh.org"; // set a key value
Var a = localStorage. fresh; // obtain the key value

Or use its API:
Javascript

The Code is as follows:
// Clear storage
LocalStorage. clear ();
// Set a key value
LocalStorage. setItem ("fresh", "vfresh.org ");
// Obtain a key value
LocalStorage. getItem ("fresh ");
// Return "vfresh.org" // obtain the name of the specified key (like Array)
LocalStorage. key (0 );
// Return "fresh" // delete a key value
LocalStorage. removeItem ("fresh ");
SessionStorage is the same, so you don't need to talk nonsense. It is equivalent to our cookie with the expiration time Expire = 0;

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.