扩展名:chrome.storage SET

时间:2016-12-08 11:09:19

标签: javascript html css google-chrome google-chrome-extension

大家好:)

my other post where we solved the GET. 好吧,我让基地再次工作 - 我想。 现在我真的不知道chrome存储的SET命令是如何工作的。

这应该设置/保存具有此ID的框中的值:“ts_id_js_html”

var input_id = document.getElementById("ts_id_js_html").value;
chrome.storage.local.set({"ts_id_js": input_id});

这是(应该)从中获取价值的地方:

<form>
   <input id="ts_id_js_html" type="text" value="128856"></input>
   <button id="execButton">Save/Load</button>
</form> 

1 个答案:

答案 0 :(得分:0)

我实际上已经解决了这个问题:

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 });

现在唯一的问题是,由于某种原因,它无法在chrome扩展弹出窗口中获取输入。每当我尝试获取ID时,我需要先添加

chrome.storage.local.get("ts_id_js", function (obj) {

代码前面,然后在最后关闭它

});

(如果其他人使用此代码,请不要忘记更改所有必要的部分!(ts_id_js,input_id,obj(obj.ts_id_js))

相关问题