我正在制作Chrome扩展程序,而我将要使用的一些功能将使用jQuery。我在网上找到有效的解决方案时遇到了麻烦。
core.js:
$(document).ready(function(){
init();
});
function init()
{
$(":button").click(function(){
console.log("test");
//more code here...
});
}
extension.html:
<html>
<head>
<title>awesome</title>
<script src="scripts/core.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
</head>
<body>
<button id="getThem">GET!</button>
</body>
</html>
在我的清单中,我有名称,版本,manifest_version(2),description,browser_action-&gt; default_popup(extention.html),我不确定要为其余部分放置什么。你能帮我把这些基本元素拼凑起来吗?
答案 0 :(得分:1)
由于Content Security policy,Chrome扩展程序中的页面无法加载外部脚本。如果您inspect the popup,控制台会显示此错误。
最好的解决方案是将(jQuery)库与您的扩展程序捆绑在一起 - 这不需要额外费用,并且可以加快弹出窗口的负担。
如果确实想要从外部网址relax the Content Security policy嵌入脚本,例如..
"content_security_policy": "script-src 'self' https://ajax.googleapis.com; object-src 'self'"
这只能针对https方案进行。如果你想从一个http资源加载,你运气不好(实际上a work-around,但请不要使用它。)。