AGa*_*yer 4 google-chrome-extension
我在我的 chrome 扩展中存储了一些选项。使用 localStorage.setItem()。
But when I want to use them on a page, it's not working. I know it's because they are totally in different domains, but how can I reach the settings in my chrome extension domain from any other domain (in my page scripts).
Thanks,
You could use the chrome.storage API.
To save something locally:
chrome.storage.sync.set({"key":"value"});
Run Code Online (Sandbox Code Playgroud)
To retrieve a value:
chrome.storage.sync.get("key",function(res) {
console.log(res[key])
});
Run Code Online (Sandbox Code Playgroud)
If you don't want the storage to sync across the user's account, you can use chrome.storage.local instead of chrome.storage.sync
| 归档时间: |
|
| 查看次数: |
2141 次 |
| 最近记录: |