【发布时间】:2015-03-01 20:16:47
【问题描述】:
我正在设计我的第一个 chrome 扩展程序,但遇到了问题。
在我的 popups.js 上,用户可以输入以数组形式保存在 chrome 存储中的单词和定义:
function save()
{
chrome.storage.local.set({'words': words});
chrome.storage.local.set({'definitions': definitions});
}
然后我想在我的内容脚本 js 中加载这些单词和定义,如下所示:
function load()
{
//load words from local storage
chrome.storage.local.get('words', function (result) {
if (result.words != "null") words = result.words;
});
//load definitions
chrome.storage.local.get('definitions', function (result) {
if (result.definitions != "null") definitions = result.definitions;
});
}
但是它根本不加载数据。我已确保在运行内容脚本之前保存数据。
我已经研究过消息传递,但并不真正理解它/不知道这是否是正确的方法。
帮助表示赞赏!
【问题讨论】:
标签: google-chrome local-storage content-script