File tree Expand file tree Collapse file tree 3 files changed +1497
-1451
lines changed Expand file tree Collapse file tree 3 files changed +1497
-1451
lines changed Original file line number Diff line number Diff line change @@ -270,18 +270,19 @@ tags:
270270 ```
271271
272272### sessionStorage
273+ - sessionStorage同样支持上述localStorage的特性和API
274+ - 在单页应用中,sessionStorage与localStorage作用范围并无差异,建议使用sessionStorage,因为可以利用其有效期,在网页一关闭便会删除本地数据,避免数据不被使用时被泄露
275+ - session storage可以多窗口共享,前提是新窗口是在当前页打开,且同源。打开方式有` window.open ` 和` <a target="_blank" href=""> `
273276
274- - sessionStorage 同样支持上述 localStorage 的特性和 API
275-
276- - 在单页应用中,sessionStorage 与 localStorage 作用范围并无差异,建议使用 sessionStorage,因为可以利用其有效期,在网页一关闭便会删除本地数据,避免数据不被使用时被泄露。
277-
278- ### cookie、localStorage、sessionStorage 在存储大小、作用范围、作用有效期的比较
277+ ### cookie、localStorage、sessionStorage的比较
279278
280279| | localStorage | sessionStorage | cookie |
281280| ---------- | ------------ | -------------------------------- | ---------------------------------------- |
282281| 存储大小 | 不超过 5MB | 不超过 5MB | 不超过 4KB(即名字和值的总量不超过 4KB) |
283282| 作用范围 | 同源 | 同源且同顶级窗口 | 同源 |
284283| 作用有效期 | 永久有效 | 在顶级窗口或当前标签页关闭前有效 | 在到达过期时间前有效,即使期间浏览器关闭 |
284+ | 安全性 | 请求时不自动携带 | 请求时不自动携带 | 请求时自动携带 |
285+ | 场景 | 存储较大数据,如用户数据、通用业务数据;用户浏览记录,如用户的阅读进度、购物车;用户偏好设置,如语言、主题等;用户行为跟踪与分析 | -- | 存储用户认证与登录状态 |
285286
286287## Web 数据库存储
287288
You can’t perform that action at this time.
0 commit comments