http和https相同的localStorage? [英] same localStorage for http and https?
问题描述
我正在寻找一种方法来为 http:// example .com
和 https使用相同的localStorage(或类似的) // example .com
根据这个,这是不可能的使用localStorage。尽管对于chrome似乎没有 globalStorage
。
我这样做是为了扩展chrome,所以使用cookies不是一种选择,不需要与其他浏览器兼容。
有什么想法?如果你只需要在localStorage上的网站存储时间,那么你不需要解决这个http / https问题。扩展程序有自己独立的localStorage,您可以随时随地访问,因此只需将数据存储在那里即可。
只能从背景页面访问此localStorage,脚本你需要先发送请求到后台页面,然后在localStorage上工作:
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;
}
});
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 other 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;
}
});
这篇关于http和https相同的localStorage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!