问题描述
我正在为 Google Chrome 开发一个扩展程序,但遇到了一些问题.我创建了一个 options.html 页面并将其添加到 manifest.json 文件中.该页面显示正常.
I'm developing an extension for Google Chrome, and have run into some trouble.I created an options.html page and added it to the manifest.json file.The page shows properly.
我保存了选项,然后返回到应该运行扩展程序的页面.
I saved the options, and then went back to the page on which the extension is supposed to run.
不幸的是,选项的本地存储返回空"而不是选项.如果我直接从扩展的 JS 脚本设置本地存储选项,它可以正常工作,但如果它是从选项页面设置的,则不能.
Unfortunately, the Local storage for the options was returning a 'null' instead of the option. If I set the local storage option directly from the extension's JS script, it works fine but not if it was set from the options page.
知道如何从扩展程序中的 Javascript 文件访问 options.html 本地存储值吗?
Any idea how i can access the options.html local storage values from my Javascript file in the extension?
推荐答案
您可以使用任一方法设置它们
You can set them using either
localStorage["var"]=data;
或
localStorage.var=data;
使用
var myvar = localStorage.var;
您可以阅读 API 此处.
You can read about the API here.
这篇关于谷歌浏览器扩展:本地存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!