Home > Web Front-end > H5 Tutorial > body text

html5 web local storage will replace our cookies_html5 tutorial tips

WBOY
Release: 2016-05-16 15:50:40
Original
1247 people have browsed it

HTML5 provides us with a local caching mechanism that will replace our cookies, and it will not be sent to our server with the browser. We can use js to freely operate the local cache on the client side. The cache in html5 mainly includes localStorage and sessionStorage. Their usage is consistent. The difference is that their time limits are different. There is no time limit for localStorage. SessionStorage is based on session data storage. After closing or leaving the website, the data will be deleted.

Let’s take a brief look at the official sample operation:
javascript

Copy code
The code is as follows:

localStorage.fresh = “vfresh.org”; //Set a key value
var a = localStorage.fresh; //Get the key value

Or use its API:
javascript

Copy code
The code is as follows:

//Clear storage
localStorage.clear();
//Set a key value
localStorage.setItem("fresh", "vfresh .org");
//Get a key value
localStorage.getItem("fresh");
//return "vfresh.org" //Get the name of the key with the specified subscript (like Array)
localStorage.key(0);
//return “fresh” //Delete a key value
localStorage.removeItem(“fresh”);
sessionStorage is the same, so there is no need to talk nonsense, it is quite Cookies with our expiration time Expire=0;
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!