Home > Web Front-end > H5 Tutorial > html5 web storage

html5 web storage

大家讲道理
Release: 2017-05-28 11:06:50
Original
2030 people have browsed it

In the past, we used document.cookie to store data locally, but because its storage size is only about 4K, The parsing is also very complicated, which brings a lot of inconvenience to development. But now html5 has web storage, which makes up for the shortcomings of cookies, and it is also quite convenient to open it

Web storage is divided into two categories

sessionStorage

The capacity is approx. It is about 5M, and the life cycle of this method is until the browser window is closed

##localStorage

The capacity is about 20M. The stored data will not expire when the user's browsing session expires, but will be deleted at the user's request. Browsers also delete them due to storage space limitations or security reasons. And the data stored in the type can be shared by multiple windows of the same browser

Notes: Only string can be stored. If it is jsonobject, the object can be JSON.stringify () Detailed explanation of the

method after encoding:

 

setItem(key, value) Set storage content

getItem(key)

Read storage content

removeItem(key)

Remove the key value to The storage content of key

 

clear() Clear all storage contents

Let’s do this Let me show you how he writes:


  //更新
    function update() {
        window.sessionStorage.setItem(key, value);
    }    //获取
    function get() {
        window.sessionStorage.getItem(key);
    }    //删除
    function remove() {
        window.sessionStorage.removeItem(key);
    }    //清空所有数据
    function clear() {
        window.sessionStorage.clear();
    }
Copy after login


To check the effect, we take Google Chrome as an example:

The old version did not have Application, and the old version was

Resource

After storing the data

I will show you a classic example of

recording username and password

When the

checkbox for remember password is checked, the username and password do not need to be re-entered the next time you open it

html part:









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