Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用chrome.storage.get获取变量_Javascript_Google Chrome_Google Chrome Extension - Fatal编程技术网

Javascript 使用chrome.storage.get获取变量

Javascript 使用chrome.storage.get获取变量,javascript,google-chrome,google-chrome-extension,Javascript,Google Chrome,Google Chrome Extension,我正在做一个小小的Chrome扩展,我已经成功地使用选项页面使用Chrome.storage.sync.set来设置变量pws。但是,在弹出页面上,我无法成功检索变量并在字符串中使用它。下面是代码: weather.open("GET", "http://api.wunderground.com/api/"+WU_API_KEY+"/conditions/q/CA/pws:"+pws+".json", true); weather.send() }) 如何从chrome.sync.stora

我正在做一个小小的Chrome扩展,我已经成功地使用选项页面使用Chrome.storage.sync.set来设置变量pws。但是,在弹出页面上,我无法成功检索变量并在字符串中使用它。下面是代码:

weather.open("GET", "http://api.wunderground.com/api/"+WU_API_KEY+"/conditions/q/CA/pws:"+pws+".json", true);
weather.send()

})
如何从chrome.sync.storage.get中获取pws作为变量

我试过类似的东西

chrome.storage.sync.get(pws, function(result){

var pws = result.pws
console.debug('result:',pws);

});
但是没有用。

如果您使用
“pws”
作为存储
pws
的键,那么您可以:

chrome.storage.sync.get("pws", function(result) {
    var pws = result.pws;
    console.log("result:", pws);
});
如果使用
“pws”
作为存储
pws
的键,则可以:

chrome.storage.sync.get("pws", function(result) {
    var pws = result.pws;
    console.log("result:", pws);
});

谢谢这很有帮助。伊桑克斯!这很有帮助。我