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.变量名称 = 值
Value:
window.localStorage.getItem(“变量名称”)-à localStorage.变量名称
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 .变量名称 = 值
Value:
window. sessionStorage .getItem(“变量名称”)-à sessionStorage .变量名称 sessionStorage:
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>
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!