How to localStorage properly with one name?
I want to use localStorage["something"] = item; but the script is loaded in every page, which creates 开发者_开发技巧files like:
http_www.google.bg_0.localstorage
http_stackoverflow.com_0.localstorage`
I want the current webpage data to be stored in one file, just like the normal extensions do. But I found that this is possible only while localStorage is accessed from popups.html. Then the outputted file is like:
chrome-extension_cognfheolmcnfppokallnahdaibbaabe_0.localstorage
Does somebody knows how to do that? Or maybe how to use the localStorage from popup.html, without showing it?
EDIT:
When I try to use a function from the background.html like:
chrome.extension.getBackgroundPage().setItem("currentWord",s);
Nothing gets called, whu could this happen?
Here's my background.html:
<html><head><script>
var logging = false;
function setItem(key, value) {
alert("Saving setting");
try {
log("Inside setItem:" + key + ":" + value);
window.localStorage.removeItem(key);
window.localStorage.setItem(key, value);
} catch(e) {
alert("Error inside setItem: " + e);
}
}
function clear() {
window.localStorage.clear();
}
function log(txt) {
if(logging) console.log(txt);
}
</script></head></html>
You need to put values to a local storage inside a background page. In order to do that you need to pass your value there from a content script using message passing.
精彩评论