[英]Chrome Extension using jQuery not working
I'm trying to build a very simple Chrome Extension with a jQuery menu - it's based in some code I gathered online. 我正在尝试使用jQuery菜单构建一个非常简单的Chrome扩展程序-它基于我在线收集的一些代码。 When I test the HTML in a browser it works, the problem is when I test as a Chrome Extension.
当我在浏览器中测试HTML时,它可以工作,问题是当我作为Chrome扩展程序进行测试时。
Is there anything missing in the manifest file? 清单文件中是否缺少任何内容?
Thanks 谢谢
Here are the files: 这些是文件:
manifest.json manifest.json
{
"name": "name",
"description": "desc",
"version": "1.4",
"manifest_version": 2,
"browser_action": {
"default_icon": "ari.png",
"default_popup": "popup.html"
},
"permissions": [
"tabs",
"http://*/",
"https://*/",
"file:///*/*",
"https://*.google.com/"
]
"content_scripts": [{
"matches": ["http://*/*"]
"js": [
"jquery.js",
"popup.js"
],
}
popup.html popup.html
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>title</title>
<script src="jquery.js"></script>
<script src="popup.js"></script>
<style>
</style>
<!--
- JavaScript and HTML must be in separate files: see our Content Security
- Policy documentation[1] for details and explanation.
-
- [1]: http://developer.chrome.com/extensions/contentSecurityPolicy.html
-->
</head>
<body>
<div style="float:left" > <!--This is the first division of left-->
<p><strong>Report by region</strong></p>
<div id="firstpane" class="menu_list"> <!--Code for menu starts here-->
<p class="menu_head">Header-1</p>
<div class="menu_body">
<a href="#">Link-1</a>
<a href="#">Link-2</a>
<a href="#">Link-3</a>
</div>
<p class="menu_head">Header-2</p>
<div class="menu_body">
<a href="#">Link-1</a>
<a href="#">Link-2</a>
<a href="#">Link-3</a>
</div>
<p class="menu_head">Header-3</p>
<div class="menu_body">
<a href="#">Link-1</a>
<a href="#">Link-2</a>
<a href="#">Link-3</a>
</div>
</div> <!--Code for menu ends here-->
</div>
<div style="float:left; margin-left:20px;"> <!--This is the second division of right-->
<p><strong>Works with mouse over</strong></p>
<div class="menu_list" id="secondpane"> <!--Code for menu starts here-->
<p class="menu_head">Header-1</p>
<div class="menu_body">
<a href="#">Link-1</a>
<a href="#">Link-2</a>
<a href="#">Link-3</a>
</div>
<p class="menu_head">Header-2</p>
<div class="menu_body">
<a href="#">Link-1</a>
<a href="#">Link-2</a>
<a href="#">Link-3</a>
</div>
<p class="menu_head">Header-3</p>
<div class="menu_body">
<a href="#">Link-1</a>
<a href="#">Link-2</a>
<a href="#">Link-3</a>
</div>
</div> <!--Code for menu ends here-->
</div>
</body>
</html>
popup.js popup.js
<!--//---------------------------------+
// Developed by Roshan Bhattarai
// Visit http://roshanbh.com.np for this script and more.
// This notice MUST stay intact for legal use
// --------------------------------->
$(document).ready(function()
{
//slides the element with class "menu_body" when paragraph with class "menu_head" is clicked
$("#firstpane p.menu_head").click(function()
{
$(this).css({backgroundImage:"url(down.png)"}).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
$(this).siblings().css({backgroundImage:"url(left.png)"});
});
//slides the element with class "menu_body" when mouse is over the paragraph
$("#secondpane p.menu_head").mouseover(function()
{
$(this).css({backgroundImage:"url(down.png)"}).next("div.menu_body").slideDown(500).siblings("div.menu_body").slideUp("slow");
$(this).siblings().css({backgroundImage:"url(left.png)"});
});
});
You are missing some closing brackets 您缺少一些右括号
"content_scripts": [{
"matches": ["http://*/*"],
"js": [
"jquery.js",
"popup.js"
]
}]
The manifest looks fine, so I'm suspecting a directory structure problem. 清单看起来不错,所以我怀疑目录结构有问题。
'not working' is a pretty broad description of your problem. “无效”是对您的问题的广泛描述。 Post some console out put and throw in what your directory structure look like too.
也将一些控制台发布并放入您的目录结构。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.