当前位置:网站首页>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保存的数据.
边栏推荐
- wc、grep、tar、vi/vim
- The spark operator - coalesce operator
- 单臂路由与三成交换机
- Spark source code-task submission process-6.2-sparkContext initialization-TaskScheduler task scheduler
- Dsf5.0 bounced points determine not return a value
- Wechat applet page jump to pass parameters
- By solving these three problems, the operation and maintenance efficiency will exceed 90% of the hospital
- [Day1] (Super detailed steps) Build a soft RAID disk array
- 解决这三大问题,运维效率将超90%的医院
- I217-V network disconnection problem in large traffic under openwrt soft routing
猜你喜欢

VRRP principle and command

The highlight moment of operation and maintenance starts with intelligence

VLAN介绍与实验

network issue?Service packet loss?This is enough

The problem of calling ds18b20 through a single bus

Image compression failure problem

I/O性能与可靠性

ALC实验

深度 Zabbix 使用指南——来自惨绿少年

What?CDN cache acceleration only works for accelerating static content?
随机推荐
[Day5] Soft and hard links File storage, deletion, directory management commands
time complexity and space complexity
Getting Started Doc 08 Conditional Plugins
Will intelligent operation and maintenance replace manual operation and maintenance?
What's the point of monitoring the involution of the system?
Getting Started Doc 06 Adding files to a stream
[ingress]-ingress使用tcp端口暴露服务
Getting Started Documentation 10 Resource Mapping
Call the TensorFlow Objection Detection API for object detection and save the detection results locally
交换机原理
Unity realizes first-person roaming (nanny-level tutorial)
Getting Started 04 When a task depends on another task, it needs to be executed in sequence
idea 常用快捷键
有哪些事情是你做了运维才知道的?
路由器和静态路由的配置
VLAN详解及实验
Proprietary host CDH
IP address and subnet division
Getting Started Document 07 Staged Output
Getting Started Document 09 Standalone watch