当前位置:网站首页>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保存的数据.
边栏推荐
猜你喜欢
正则表达式小实例--验证邮箱地址
网络布线与数制转换
入职前,没想到他们玩的这么花
Unity realizes first-person roaming (nanny-level tutorial)
RAID磁盘阵列
Getting Started 04 When a task depends on another task, it needs to be executed in sequence
OpenCV3.0 is compatible with VS2010 and VS2013
交换机原理
Three modes of vim
spark operator - map vs mapPartitions operator
随机推荐
Network wiring and digital-to-system conversion
What's the point of monitoring the involution of the system?
[Day1] VMware software installation
NIO工作方式浅析
从“双卡双待“到”双通“,vivo率先推动DSDA架构落地
Hard Disk Partitioning and Permanent Mounting
云计算——osi七层与TCP\IP协议
Switch principle
User and user group management, file permission management
传输层协议
Account and Permission Management
Mongodb查询分析器解析
技术分享杂七杂八技术
VLAN介绍与实验
Spark source code-task submission process-6.2-sparkContext initialization-TaskScheduler task scheduler
Call the TensorFlow Objection Detection API for object detection and save the detection results locally
Introductory document 05-2 use return instructions the current task has been completed
LeetCode面试题
网络不通?服务丢包?看这篇就够了
交换机原理