当前位置:网站首页>localStorage与sessionStorage
localStorage与sessionStorage
2022-07-27 00:28:00 【io无心】
cookie/localStorage/sessionStorage之间的区别
- 保存方式区别:cookie数据始终在同源的http请求中携带,即cookie会在浏览器和服务器之间来回传递,但可以通过路径限制其只属于某个路径下有效。而sessionStorage和localStorage不会把数据发给服务器,仅在本地保存。
- 存储大小限制不同:cookie数据不能超过4K,只适合保存很小的数据,如会话标识。sessionStorage和localStorage可存储的大小在5M左右。
- 数据有效期不同:sessionStorage仅在当前浏览器窗口关闭前有效;localStorage始终有效,窗口或浏览器关闭也一直保存;cookie只在设置的cookie过期时间之前一直有效,即使窗口或浏览器关闭。
- 作用域不同:sessionStorage不在不同的浏览器窗口中共享,即使是同一个页面;localStorage和cookie在所有同源窗口中共享。
localStorage的方法
- localStorage.setItem("key","value"); 添加一个键值对
- localStorage.getItem("key"); 通过key查询value
- localStorage.removeItem("key"); 删除key对应的键值对
- localStorage.clear(); 清除全部的键值对
sessionStorage的方法(与localStorage方法一样)
- sessionStorage.setItem("key","value"); 添加一个键值对
- sessionStorage.getItem("key"); 通过key查询value
- sessionStorage.removeItem("key"); 删除key对应的键值对
- sessionStorage.clear(); 清除全部的键值对
边栏推荐
- Interview shock 68: why does TCP need three handshakes?
- LabVIEW中编程更改进程的优先级
- 哈希表与一致性哈希的原理理解以及应用
- ansible系列之:不收集主机信息 gather_facts: False
- C language program compilation
- Tabbar of customized wechat applet on uni app
- C语言程序的编译(预处理)下
- Rust web (I) -- self built TCP server
- [NISACTF 2022]上
- How small programs help the new model of smart home ecology
猜你喜欢

Ten thousand words long text, take you to understand the kubernetes network model

C language: deep learning recursion

用最原始的方法纯手工实现常见的 20 个数组方法

setTimeout第一个参数应该注意的地方

Okaleido tiger is about to log in to binance NFT in the second round, which has aroused heated discussion in the community

万字长文,带你搞懂 Kubernetes 网络模型

static关键字

Static keyword

Goatgui invites you to attend a machine learning seminar

「软件测试」包装简历从这几点出发,直接提升通过率
随机推荐
Non global function of lua function
面试突击68:为什么 TCP 需要 3 次握手?
单例模式(双检锁)
Redis installation and operation (Linux)
Goatgui invites you to attend a machine learning seminar
云开发寝适闹钟微信小程序源码
杀毒软件 clamav 的安装和使用
MySQL 5.7 takes the first item of the group
[redis] five common data types
CS224W fall 1.2 Applications of Graph ML
Okaleido tiger logged into binance NFT on July 27, and has achieved good results in the first round
Pyqt5 use pyqtgraph to draw dynamic scatter chart
Greed - 376. Swing sequence
「软件测试」包装简历从这几点出发,直接提升通过率
小玩一个并行多线程MCU—MC3172
B-树的应用以及添加和删除操作
Web3.0 world knowledge system sharing - what is Web3.0
如何白嫖最新版BurpSuite Pro
c语言:深度学习递归
Ten thousand words long text, take you to understand the kubernetes network model