Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要从全局加载的脚本访问活动 Web 浏览器选项卡的本地存储。可能吗?如果是,您能否提供示例?ps code "window.localStorage[key]" 从全局存储中获取信息。网络浏览器:Safari、Mac OS。
谢谢
没有“全局存储”之类的东西。localStorage在打开相同域的选项卡之间共享,仅此而已。
localStorage
我建议在您的 中添加某种标识符key,以获取当前选项卡/窗口的数据:
key
var currentTabId = parseInt(localStorage.tabIds || -1) + 1; localStorage.tabIds = currentTabId; localStorage['myKey' + currentTabId] = "Some data";