Chrome扩展程序:仅存储一个存储变量的存储侦听器 [英] Chrome extensions: storage listener for only one stored variable
本文介绍了Chrome扩展程序:仅存储一个存储变量的存储侦听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
popup.js:
...
chrome.storage.sync.set({'source': source, 'active': active, 'secs': secs, 'domain': domain}, function() {
console.log('Settings saved');
});
...
background.js:
background.js:
chrome.storage.onChanged.addListener(function(tab) {
//something
});
那么,我可以添加一个侦听器来监听(例如)活动"吗?
So, can I add a listener for changes of (for example) 'active'?
推荐答案
您必须在侦听器中为特定键添加if或switch语句,就像这样;
You'd have to add an if or switch statement in the listener for specific keys, like so;
chrome.storage.onChanged.addListener(function(changes, namespace) {
for(key in changes) {
if(key === 'active') {
// Do something here
}
}
});
这篇关于Chrome扩展程序:仅存储一个存储变量的存储侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文