Javascript 使用chrome.storage.get获取变量
我正在做一个小小的Chrome扩展,我已经成功地使用选项页面使用Chrome.storage.sync.set来设置变量pws。但是,在弹出页面上,我无法成功检索变量并在字符串中使用它。下面是代码: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
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);
});
谢谢这很有帮助。伊桑克斯!这很有帮助。我