当前位置:网站首页>浏览器存储WebStorage
浏览器存储WebStorage
2022-08-05 05:22:00 【-小龙人】
介绍
浏览器存储WebStorage包括 LocalStorage 和 SessionStorage,存储内容大小一般在5M左右。
如何使用
浏览器通过Window.localStorage 和 Window.sessionStorage属性来实现本地存储机制,在实际使用中可省略Window。
API使用
LocalStorage 和 SessionStorage的API方法名称用法相同,分别有新增、获取、删除、清空四个方法,方法名称及使用方法见下面示例:
//新增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区别
同为浏览器储存的WebStorage,LocalStorage 和 SessionStorage使用的API相同,但实际使用场景是有区别的:
LocalStorage
使用localStorage保存的数据会长期保留,即使你关闭浏览器下次重新打开该页面,保存的数据依然还在不会被清空,如果需要清空必须手动清除。而且在同个浏览器相同源(window.location.origin)的其他页面都是可以通过 localStorage 访问到,当然了源与源之间的 localStorage 是不能互相访问的。即每个源之间的 localStorage 是相互独立的。SessionStorage
使用sessionStorage保存的数据只是当前页面会保留,即页面会话级别,当关闭浏览器或者关闭页签后sessionStorage保存的数据会被清空,而且在同个浏览器即使相同源,其他页面不可以共享sessionStorage保存的数据。
边栏推荐
- VLAN详解及实验
- spark operator-parallelize operator
- 网络布线与数制转换
- 技术分享杂七杂八技术
- [Day5] Soft and hard links File storage, deletion, directory management commands
- LinkSLA坚持用户第一,打造可持续的运维服务方案
- Apache configure reverse proxy
- Getting Started 11 Automatically add version numbers
- 有哪些事情是你做了运维才知道的?
- The highlight moment of operation and maintenance starts with intelligence
猜你喜欢

I/O performance and reliability

The problem come from line screening process

Hugo搭建个人博客

解决这三大问题,运维效率将超90%的医院
![[Paper Intensive Reading] The relationship between Precision-Recall and ROC curves](/img/8f/3c9944db96eef623779a5abe68355b.png)
[Paper Intensive Reading] The relationship between Precision-Recall and ROC curves

Why can't I add a new hard disk to scan?How to solve?

By solving these three problems, the operation and maintenance efficiency will exceed 90% of the hospital

入门文档05 使用cb()指示当前任务已完成

入门文档04 一个任务依赖另外一个任务时,需要按顺序执行
![[Day8] Commands involved in using LVM to expand](/img/ba/39b81cbcecec9bc54a710ff9dba81a.png)
[Day8] Commands involved in using LVM to expand
随机推荐
入门文档01 series按顺序执行
vim的三种模式
spark source code - task submission process - 1-sparkSubmit
入门文档08 条件插件
The highlight moment of operation and maintenance starts with intelligence
network issue?Service packet loss?This is enough
单臂路由与三成交换机
The problem of redirecting to the home page when visiting a new page in dsf5.0
Technology Sharing Miscellaneous Technologies
The problem of calling ds18b20 through a single bus
ACLs and NATs
单臂路由实验和三层交换机实验
spark source code - task submission process - 5-CoarseGrainedExecutorBackend
time complexity and space complexity
LinkSLA坚持用户第一,打造可持续的运维服务方案
硬盘分区和永久挂载
错误类型:反射。ReflectionException:无法设置属性“xxx”的“类”xxx”与价值“xxx”
[Day8] Commands involved in using LVM to expand
By solving these three problems, the operation and maintenance efficiency will exceed 90% of the hospital
入门文档09 独立的watch