问题
Hello everyone :)
my other post where we solved the GET. Ok, I got the base working once again - i think. Now I really don't know how the SET command of chrome storage works.
This should set/save the value that is in a box with this ID: "ts_id_js_html"
var input_id = document.getElementById("ts_id_js_html").value;
chrome.storage.local.set({"ts_id_js": input_id});
This is where it (should)get the Value from:
<form>
<input id="ts_id_js_html" type="text" value="128856"></input>
<button id="execButton">Save/Load</button>
</form>
回答1:
I actually got it working with this:
chrome.storage.local.set({"ts_id_js": input_id}, function (obj) { chrome.storage.local.get("ts_id_js", function (obj) { console.log("ts_id_js INSIDE func. test (is this your ID?):" + obj.ts_id_js); //this line is for test output in console });
Only issue now is, that it fails to get the input in the chrome extension popup for some reason. Whenever I try to GET the ID I need to first add
chrome.storage.local.get("ts_id_js", function (obj) {
infront of the code, and then close it at the end
});
(if someone else uses this code, DON'T forget to change all parts that are necessary! (ts_id_js, input_id, obj (obj.ts_id_js))
来源:https://stackoverflow.com/questions/41038011/extension-chrome-storage-set