当前位置:网站首页>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保存的数据.
边栏推荐
- network issue?Service packet loss?This is enough
- The problem of calling ds18b20 through a single bus
- Small example of regular expression--validate email address
- Hugo builds a personal blog
- 用户和用户组管理、文件权限管理
- VLAN details and experiments
- The problem of redirecting to the home page when visiting a new page in dsf5.0
- Mina断线重连
- 磁盘管理与文件系统
- Mongodb查询分析器解析
猜你喜欢

vim教程:vimtutor

单臂路由实验和三层交换机实验

Dsf5.0 bounced points determine not return a value

实力卷王LinkSLA,实现运维工程师快乐摸鱼

What are some things that you only know when you do operation and maintenance?
![[Day8] (Super detailed steps) Use LVM to expand capacity](/img/ff/d4f06d8b30148496da64360268cf1b.png)
[Day8] (Super detailed steps) Use LVM to expand capacity

I/O性能与可靠性

Hard Disk Partitioning and Permanent Mounting

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

静态路由
随机推荐
[Day1] (Super detailed steps) Build a soft RAID disk array
ACL 和NAT
Spark source code - task submission process - 6-sparkContext initialization
Switch principle
Hugo搭建个人博客
Configuration of TensorFlow ObjecDetectionAPI under Anaconda3 of win10 system
ROS video tutorial
Mina断线重连
In-depth Zabbix user guide - from the green boy
js动态获取屏幕宽高度
Three modes of vim
sql server 重复值在后面计数
spark operator - map vs mapPartitions operator
Apache configure reverse proxy
618, you may be able to wake up a little bit
Hugo builds a personal blog
Unity realizes first-person roaming (nanny-level tutorial)
Cloud computing - osi seven layers and TCP\IP protocol
Disk management and file systems
Why can't I add a new hard disk to scan?How to solve?