简体   繁体   English

访问活动页面的本地存储

[英]Access to local storage of active page

I need to access to local storage of active web-browser tab from script which globally loaded. 我需要从全局加载的脚本访问活动Web浏览器选项卡的本地存储。 Is it possible? 可能吗? If yes, could you please provide example? 如果是,请提供示例吗? ps code "window.localStorage[key]" gets info from global storage. ps代码“ window.localStorage [key]”从全局存储获取信息。 Web-browser: Safari, Mac OS. 网络浏览器:Safari,Mac OS。

Thanks 谢谢

There is no such thing as "Global Storage" . 没有“全局存储”之类的东西。 localStorage is shared across tabs that have the same domain open, but that's it. 在具有相同域打开的选项卡之间共享localStorage ,仅此而已。

I'd suggest adding some kind of identifier to your key , to get data for the current tab / window: 我建议在您的key添加某种标识符,以获取当前标签页/窗口的数据:

var currentTabId = parseInt(localStorage.tabIds || -1) + 1;
localStorage.tabIds = currentTabId;

localStorage['myKey' + currentTabId] = "Some data";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM