Chrome Extension won#39;t load my JavaScript from the popup file(Chrome 扩展程序不会从弹出文件中加载我的 JavaScript)
问题描述
我正在为论坛构建 Chrome 扩展程序,但问题是我的 popup.html 的 JavaScript 无法执行任何操作.我在顶部添加了 alert("popup.js running...") 并且它确实出现了,但是我的弹出窗口根本不显示.这是一个问题,因为弹出页面需要 JavaScript.我有点迷路了,所以我假设我只是错过了一些阻止我的 JavaScript 运行的东西.我听说 AdBlock 扩展程序会阻止它运行,但我删除了它,它仍然没有工作.有人看到问题了吗?
I'm working on building a Chrome extension for a forum, but the problem is the JavaScript for my popup.html won't do anything. I added alert("popup.js running...") at the top and it does come up but then my popup doesn't display at all. This is a problem because JavaScript is going to be required for the popup page. I'm kind of lost, so I'm assuming I'm just missing something that is preventing my JavaScript from running. I heard the AdBlock extension would prevent it from running but I removed that and it still didn't work. Anyone see a problem?
manifest.json
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!");
});
推荐答案
我的扩展也遇到了同样的问题,我相信在我将它添加到清单文件后它已经解决了.
I had the same exact problem with an extension of mine, I believe it was fixed after I added this to the manifest file.
manifest.json
manifest.json
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
更多信息:http://developer.chrome.com/extensions/contentSecurityPolicy.html.
这篇关于Chrome 扩展程序不会从弹出文件中加载我的 JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Chrome 扩展程序不会从弹出文件中加载我的 JavaScript
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01