我写了一个简单的 html 页面,它有一个输入和三个链接。
"OK" --> 将文件中的任何内容存储到本地存储
"WhoamI" --> 带有保存到本地存储的值的警报
"Check" --> 如果该值为 "asd",则回复 "asd" 或不回复 "Asd"
非常简单,我已经将它作为一个普通的 html 页面进行了测试,它可以工作。所有功能都按应有的方式运行。
这是 index.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> System Information </title>
<script src="main.js"></script>
</head>
<body>
<input type="text" name="text" id="text">
<a href="#" onclick="saveChanges(); return false">OK</a>
<a href="#" onclick="who(); return false">WhoAmI</a>
<a href="#" onclick="check(); return false">check</a>
</body>
</html>
这是javascript main.js
function saveChanges() {
var theValue = text.value;
localStorage["ChromeLogin"] = theValue;
}
function who() {
alert(localStorage["ChromeLogin"]);
}
function check(){
var test = localStorage["ChromeLogin"];
if (test == "asd"){
alert("it is asd");
}else{
alert("It is NOT asd");
}
}
但是,当我导入与 google chrome 扩展相同的代码时,一切都停止工作了。
这是我的 manifest.json 代码。
{
"name": "testLocalStorage",
"version": "0.0.1",
"description": "Capture a tab",
"options_page": "index.html",
"manifest_version": 2,
"browser_action": {
"default_title": "Capture tab"
},
"permissions" : ["tabs", "<all_urls>", "storage"]
}
我假设这是问题所在:
我通读了这篇文章,但我无法弄清楚。
任何帮助将不胜感激
谢谢