有没有办法隔离不同选项卡之间的"localStorage"? [英] Is there a way to isolate 'localStorage' between different tabs?

查看:97
本文介绍了有没有办法隔离不同选项卡之间的"localStorage"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在使用window.localStorage在浏览器上存储一些客户端数据.但我想将此存储隔离到各个选项卡.

I am currently using window.localStorage to store some client side data on browser. But I'd like to isolate this storage to individual tabs.

有没有办法做到这一点?

Is there a way to achieve this?

推荐答案

您应该考虑使用

You should consider using sessionStorage instead:

sessionStorage与localStorage类似;唯一的区别是,存储在localStorage中的数据没有到期时间,而存储在sessionStorage中的数据在页面会话结束时被清除.页面会话的持续时间只要浏览器处于打开状态,并且在页面重新加载和还原后仍然存在.在新标签页或窗口中打开页面将导致使用顶级浏览上下文[...]

sessionStorage is similar to localStorage; the only difference is while data stored in localStorage has no expiration time, data stored in sessionStorage gets cleared when the page session ends. A page session lasts for as long as the browser is open and survives over page reloads and restores. Opening a page in a new tab or window will cause a new session to be initiated with the value of the top-level browsing context [...]

这篇关于有没有办法隔离不同选项卡之间的"localStorage"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆