我正在为论坛构建Chrome扩展程序,但问题是我的popup.html的JavaScript不会做任何事情。我在顶部添加了alert(“popup.js running ...”)并且它确实出现但是我的弹出窗口根本没有显示。这是一个问题,因为弹出页面将需要JavaScript。我有点迷茫,所以我假设我只是遗漏了阻止我的JavaScript运行的东西。我听说AdBlock扩展程序会阻止它运行但我删除了它仍然无法正常工作。有人看到问题吗?
的manifest.json
{
"name": "Riggy",
"short_name": "Riggy",
"description": "Create your own Roblox Forum signature with Riggy!",
"version": "0.0.1",
"manifest_version": 2,
"browser_action": {
"default_popup": "popup/popup.html"
},
"permissions": [
"storage"
],
"content_scripts": [
{
"matches": ["http://www.roblox.com/*"],
"js": ["scripts/jquery.js", "scripts/content.js"]
}
]
}
popup.html
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="popup.css" />
<script type="text/javascript" src="scripts/jquery.js"></script>
</head>
<body>
<span class="title">Riggy</span><br />
<span>Signature: </span><input name="siggy" id="siggy" value="Riggy is greatness!" />
<span id="output">[output]</span>
<script type="text/javascript" src="popup.js"></script>
</body>
</html>
popup.js
alert("popup.js running");
$(document).on("ready", function() {
var siggy = $("#siggy");
var output = $("#output");
function message(text) {
output.html(text);
}
siggy.change(function() {
chrome.storage.sync.set({"siggy": siggy.val()}, function() {
message("Saved signature.");
});
});
message("Riggy is ready!");
});
答案 0 :(得分:1)
我对我的扩展程序有同样的问题,我相信在将其添加到清单文件后它已修复。
的manifest.json
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
此处有更多信息:http://developer.chrome.com/extensions/contentSecurityPolicy.html。