Home Web Front-end H5 Tutorial html5 web storage

html5 web storage

May 28, 2017 am 11:06 AM
web

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:

<label

for=""> Username: <input type="text" class="userName"/ >
</label>
<br/><br/>
<label for="">
Password: <input type="passw
ord
" class="pwd"/> </label>
<br/><br/>
<label for="">
                                                                                                                                                                                                                                                                                      # <button>Login</button>

js part


##


The above is the detailed content of html5 web storage. For more information, please follow other related articles on the PHP Chinese website!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use python+Flask to realize real-time update and display of logs on web pages How to use python+Flask to realize real-time update and display of logs on web pages May 17, 2023 am 11:07 AM

How to use python+Flask to realize real-time update and display of logs on web pages

How to use Nginx web server caddy How to use Nginx web server caddy May 30, 2023 pm 12:19 PM

How to use Nginx web server caddy

Real-time protection against face-blocking barrages on the web (based on machine learning) Real-time protection against face-blocking barrages on the web (based on machine learning) Jun 10, 2023 pm 01:03 PM

Real-time protection against face-blocking barrages on the web (based on machine learning)

How to configure nginx to ensure that the frps server and web share port 80 How to configure nginx to ensure that the frps server and web share port 80 Jun 03, 2023 am 08:19 AM

How to configure nginx to ensure that the frps server and web share port 80

Using Jetty7 for Web server processing in Java API development Using Jetty7 for Web server processing in Java API development Jun 18, 2023 am 10:42 AM

Using Jetty7 for Web server processing in Java API development

How to implement form validation for web applications using Golang How to implement form validation for web applications using Golang Jun 24, 2023 am 09:08 AM

How to implement form validation for web applications using Golang

How to enable administrative access from the cockpit web UI How to enable administrative access from the cockpit web UI Mar 20, 2024 pm 06:56 PM

How to enable administrative access from the cockpit web UI

How to solve the problem of nginx hidden version number and WEB server information How to solve the problem of nginx hidden version number and WEB server information May 21, 2023 am 09:13 AM

How to solve the problem of nginx hidden version number and WEB server information

See all articles