当前位置:网站首页>Browser Storage WebStorage
Browser Storage WebStorage
2022-08-05 06:20:00 【-Little Dragon Man】
介绍
浏览器存储WebStorage包括 LocalStorage 和 SessionStorage,The storage content size is generally in5M左右.
如何使用
浏览器通过Window.localStorage 和 Window.sessionStorage属性来实现本地存储机制,It can be omitted in actual useWindow.
API使用
LocalStorage 和 SessionStorage的APIThe method name usage is the same,added respectively、获取、删除、Empty four methods,See the example below for the method name and how to use it:
//新增WebStorage: setItem(key,val)
localStorage.setItem("a", "123");
localStorage.setItem("b", "456");
localStorage.setItem("c", "789");
sessionStorage.setItem("a", "123");
sessionStorage.setItem("b", "456");
sessionStorage.setItem("c", "789");
//获取WebStorage: getItem(key)
localStorage.getItem("a");
sessionStorage.getItem("a");
//删除WebStorage: removeItem(key)
localStorage.removeItem("c");
sessionStorage.removeItem("c");
//清空WebStorage: removeItem(key)
localStorage.clear();
sessionStorage.clear();
LocalStorage 和 SessionStorage区别
Also stored in the browserWebStorage,LocalStorage 和 SessionStorage使用的API相同,But the actual usage scenarios are different:
LocalStorage
使用localStorageSaved data is retained for a long time,Even if you close the browser next time you reopen the page,The saved data will still not be cleared,If it needs to be cleared, it must be cleared manually.And the same source in the same browser(window.location.origin)All other pages are accessible localStorage 访问到,Of course between source and source localStorage 是不能互相访问的.i.e. between each source localStorage 是相互独立的.SessionStorage
使用sessionStorageThe saved data will remain only for the current page,That is, the page session level,When closing the browser or closing the tabsessionStorageSaved data will be cleared,And in the same browser even the same source,Other pages cannot be sharedsessionStorage保存的数据.
边栏推荐
猜你喜欢
![[问题已处理]-虚拟机报错contains a file system with errors check forced](/img/07/1222a44dd52b359bf7873e6f3b7ebf.png)
[问题已处理]-虚拟机报错contains a file system with errors check forced

ALC实验

Mongodb查询分析器解析

The problem of redirecting to the home page when visiting a new page in dsf5.0

错误类型:反射。ReflectionException:无法设置属性“xxx”的“类”xxx”与价值“xxx”

NAT实验

教您简单几步实现工业树莓派正确安装RS232转USB驱动

云计算——osi七层与TCP\IP协议

LinkSLA坚持用户第一,打造可持续的运维服务方案

监控系统的内卷,有什么讲究?
随机推荐
[Day1] (Super detailed steps) Build a soft RAID disk array
Operation and maintenance engineer, come and pick up the wool
VLAN详解及实验
markdown编辑器模板
运维的高光时刻,从智能化开始
Account and Permission Management
Hugo builds a personal blog
Apache configure reverse proxy
spark operator - map vs mapPartitions operator
微信小程序页面跳转传参
IP packet format (ICMP protocol and ARP protocol)
Proprietary host CDH
Spark source code-task submission process-6.1-sparkContext initialization-create spark driver side execution environment SparkEnv
7 steps to complete cloud monitoring
产品学习资料
Getting Started Doc 06 Adding files to a stream
传输层协议
NIO works is analysed
User and user group management, file permission management
The Servlet to jump to the JSP page, forwarding and redirection