当前位置:网站首页>JS中localStorage和sessionStorage
JS中localStorage和sessionStorage
2022-08-02 00:14:00 【weixin_46051260】
localStorage:永久存储在本地,适合保存在本地的数据
sessionStorage:会话级的存储,敏感帐号一次登陆
相同点:
1)都是保存在浏览器端
2)不会把数据自动的发送给服务器,仅在本地保存
3)只能存储字符串,可以将对象JSON.stringify()编码之后进行存储
不同点:
1)存储大小限制不同:sessionStorage存储的大小为5M,localStorage存储大小为20M
2)数据有效期不同:
- localStorage:始终有效,窗口关闭或者浏览器关闭,一直保存,持久保存数据
- sessionStorage:仅在当前浏览器窗口关闭前有效,会话级存储
3)作用域不同:
- sessionStorage:在不同浏览器窗口不会进行共享,只有同一个页面中才ok
- localStorage:在所有的同源的窗口下可以共享的
边栏推荐
- Identify memory functions memset, memcmp, memmove, and memcpy
- Graphical LeetCode - 1161. Maximum Sum of In-Layer Elements (Difficulty: Moderate)
- Angr(十二)——官方文档(Part3)
- 【CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!)(A~D)】
- go笔记——map
- 冒泡排序函数封装
- Double queue implementation stack?Dual stack implementation queue?
- go笔记记录——channel
- What does the errorPage attribute of the JSP page directive do?
- JSP out.print()和out.write()方法的不同之处
猜你喜欢
随机推荐
PHP从txt文件中读取数据的方法
Don't concatenate strings with jOOQ
基于数据驱动的变电站巡检机器人自抗扰控制
Looking back at 5 recessionary times in history: How might this time be different?
PHP to read data from TXT file
When Netflix's NFTs Forget Web2 Business Security
MLX90640 红外热成像仪测温模块开发笔记(完整版)
路由策略
How does JSP use request to get the real IP of the current visitor?
els block deformation
Grid false data injection attacks detection based on coding strategy
Mean Consistency Tracking of Time-Varying Reference Inputs for Multi-Agent Systems with Communication Delays
CRS management and maintenance
众筹DAO“枯萎”的缩影:曾拍下《沙丘》未出版手稿的Spice DAO解散
JSP request对象功能详解说明
【CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!)(A~D)】
冒泡排序函数封装
Identify memory functions memset, memcmp, memmove, and memcpy
微软电脑管家V2.1公测版正式发布
Collection of NFT tools