Extension: chrome.storage SET

风流意气都作罢 提交于 2019-12-13 06:53:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!