简体   繁体   中英

Access to local storage of active page

I need to access to local storage of active web-browser tab from script which globally loaded. Is it possible? If yes, could you please provide example? ps code "window.localStorage[key]" gets info from global storage. Web-browser: 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.

I'd suggest adding some kind of identifier to your key , to get data for the current tab / window:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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