开发者

same localStorage for http and https?

开发者 https://www.devze.com 2023-02-14 02:53 出处:网络
i\'m looking for a way to use the same localStorage (or similar) for both http:// example .com and https:// example .com

i'm looking for a way to use the same localStorage (or similar) for both http:// example .com and https:// example .com

according to this, that's not possible using localStorage. there doesn't seem to be a globalStorage for chrome though. i'm doing this for a chrome extension, so using cookies is not an option and compatibility with ot开发者_如何学Pythonher browsers is not needed.

any ideas?


If all you need is store time spent on the site in localStorage then you don't need to solve this http/https problem. Extensions have their own isolated localStorage that you can access anytime anywhere, so just store your data there.

You can access this localStorage only from a background page, so from a content script you will need to send a request to a background page first and then work with localStorage there:

content_script.js:

chrome.extension.sendRequest({do: "save", value: "some_value"});

background.html:

chrome.extension.onRequest.addListener(function(request) {
    if(request.do == "save") {
        localStorage["param"] = request.value;
    } 
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号