Home > Web Front-end > JS Tutorial > Detailed introduction to local Web-storage storage

Detailed introduction to local Web-storage storage

php中世界最好的语言
Release: 2017-12-02 10:17:23
Original
1808 people have browsed it

This article will introduce to you the Webstorage storage classification, client and server, and introduce you to web storage. With the development of web applications, there are more and more client storages. Today I will introduce Web-storage in detail. The method of storage.

Web storage,

Localstorage

Sessionstorage:

1 Detect whether the browser supports data storage

Note: In html5 Use javascript to store and access data.

2. Localstorage setting/getting data

Stored on the client (mobile phone, tablet...) without time limit

Common methods:

Assignment :

 window.localStorage .setItem(“变量名称”,”val”) ---》localStorage.变量名称 = 值
Copy after login

Value:

window.localStorage.getItem(“变量名称”)-à localStorage.变量名称
Copy after login

Note: Testing localStorage requires testing in the php environment

3.sessionstorage Setting/getting data

Stored on the server side (sohu Food World)

Assignment:

  window. sessionStorage  .setItem(“变量名称”,”val”) ---》sessionStorage  .变量名称 = 值
Copy after login

Value:

window. sessionStorage  .getItem(“变量名称”)-à sessionStorage  .变量名称
sessionStorage:
Copy after login

Close the browser

Call: sessionStorage. removeItem(“bName”); Clear data

Case code:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<link rel="stylesheet" href="css/style.css">
</head>
<script type="text/javascript">
//window.localStorage /sessionStorage
//if(true)  true  不空  0  0.0 “0” window.localStorage 有值
if(window.localStorage){
  alert(111);  
}
if(window.sessionStorage){
  alert(222);  
}
</script>
<body>
</body>
</html>
Copy after login

I believe you have mastered the method after reading these cases. For more exciting information, please pay attention to php Chinese Other related articles online!

Related reading:

How to set the text font color of CSS

How to use the color animation of hover animation in Css3

The difference between the types of box models in CSS

The above is the detailed content of Detailed introduction to local Web-storage storage. For more information, please follow other related articles on the PHP Chinese website!

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