Javascript chrome.storage.sync.get警报不工作
我已保存此设置:Javascript chrome.storage.sync.get警报不工作,javascript,google-chrome-extension,Javascript,Google Chrome Extension,我已保存此设置: function save_options() { var tbColor = document.getElementById('Color').value; chrome.storage.sync.set({ 'tbColor': Color }, function() { var status = document.getElementById('status'); status.textContent = 'Settings were
function save_options() {
var tbColor = document.getElementById('Color').value;
chrome.storage.sync.set({
'tbColor': Color
}, function() {
var status = document.getElementById('status');
status.textContent = 'Settings were saved.';
setTimeout(function() {
status.textContent = '';
}, 750);
});
}
现在我尝试通过以下方式查看设置:
alertchrome.storage.sync.get{'tbColor'}
但我什么也没得到没有警报显示。我知道整个事情都在起作用,因为alertHello;工作
获取这些设置有什么不对?我是新来的,所以请对我放松点:{'tbColor'}是无效的语法,所以它首先会出错
此外,chrome.storage.sync.get是异步的,因此不能使用返回值
您可以使用:
chrome.storage.sync.get("tbColor", function(sync) {
alert(sync.tbColor);
});