当前位置:网站首页>浏览器存储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保存的数据。
边栏推荐
- 有哪些事情是你做了运维才知道的?
- 线上问题排查流程
- One-arm routing and 30% switch
- Three modes of vim
- 云计算——osi七层与TCP\IP协议
- Insight into the general trend of the Internet, after reading this article, you will have a thorough understanding of Chinese domain names
- Getting Started 04 When a task depends on another task, it needs to be executed in sequence
- spark source code-RPC communication mechanism
- Getting Started Document 01 series in order
- spark operator-parallelize operator
猜你喜欢

NIO works is analysed

Remembering my first CCF-A conference paper | After six rejections, my paper is finally accepted, yay!

Operation and maintenance engineer, come and pick up the wool

King power volume LinkSLA, realize operations engineer is happy fishing

Growth: IT Operations Trends Report
![[Day1] VMware software installation](/img/24/20cc77e904dbe7dc1b5224c64d6329.png)
[Day1] VMware software installation

VLAN介绍与实验
![[Day6] File system permission management, file special permissions, hidden attributes](/img/ec/7fb3fa671fac8abf389844c0f4fbe7.png)
[Day6] File system permission management, file special permissions, hidden attributes

What's the point of monitoring the involution of the system?

spark operator - map vs mapPartitions operator
随机推荐
请问下通过flink sql读取hologres 的两张表的 binlog,然后如何进行join?
VLAN详解及实验
用户和用户组管理、文件权限管理
To TrueNAS PVE through hard disk
markdown编辑器模板
Account and Permission Management
运维的高光时刻,从智能化开始
正则表达式小示例--获取重复最多的字符及其数量
错误类型:反射。ReflectionException:无法设置属性“xxx”的“类”xxx”与价值“xxx”
Call the TensorFlow Objection Detection API for object detection and save the detection results locally
The problem of redirecting to the home page when visiting a new page in dsf5.0
Dsf5.0 bounced points determine not return a value
I217-V network disconnection problem in large traffic under openwrt soft routing
智能运维会取代人工运维吗?
Logical volume creation
交换机原理
线上问题排查流程
ACL 和NAT
CIPU, what impact does it have on the cloud computing industry?
LeetCode Interview Questions