这是Chrome扩展程序,用于替换用户的新标签页。
我的jQuery没有加载,因为我的HTML中的'hello'没有警告。我应该在清单或HTML中加载jQuery吗?不管是哪种,我都认为HTML应该在同一个地方。
的manifest.json:
{
"manifest_version": 2,
"name": "Some title",
"description": "Some description.",
"version": "1.0",
"chrome_url_overrides": {
"newtab": "index.html"
},
"content_scripts": [
{
"matches": ["newtab"],
"css": ["style.css"],
"js": ["jquery.js"]
}
]
}
的index.html
<html>
<head>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
alert("hello");
$(function(){
$('#container').masonry({
// options
itemSelector : '.item',
columnWidth : 300
});
});
</script>
</head>
<body>
<!-- etc -->
答案 0 :(得分:1)
如果未在manifest.json
中明确指定权限,则无法从Chrome扩展程序中的远程位置加载脚本,您可以在manifest.json
中指定权限,也可以下载jquery并使用jQuery文件分发扩展。第二个选项(在扩展文件夹中具有jquery的本地副本)似乎更合理。
答案 1 :(得分:0)
如果index.html是你的后台页面,那么我会将jquery添加到扩展文件夹并相对引用它。
如果将其应用于页面,则按照右here所述指定内容脚本。再次,保持本地和亲戚。