我还在忙着我的第一个扩展。我只想将一些数据(数组)从 contentscripts.js 传递到 popup.js。当我在几个来源中阅读它时,最简单的方法是使用本地存储。
这是我尝试过的:
contentscripts.js(我真的不知道那个是否有效)
...
alert(isotopeIndices[0]); // Array isotopeIndices has lots entries
chrome.storage.local.set(isotopeIndices[0]); //goal would be to save the whole array: chrome.storage.local.set(isotopeIndices);
popup.js
chrome.storage.local.get(
function(isotopeIndices) {
document.getElementById('selectIsotopes').innerHTML = isotopeIndices[0];
}
);
我的弹出窗口<div id="selectIsotopes">...</div>
仅在未定义的 -Element 中显示。这就是为什么我认为它chrome.storage.local.set
根本不起作用。关于 Google-HowTo ( http://developer.chrome.com/extensions/storage.html ),一切都应该是正确的。
即使问题是,本地存储是否是传递数据的最简单方法......?
感谢您的时间和帮助!!!