Chrome扩展未捕获的ReferenceError:$未定义 [英] chrome extensions Uncaught ReferenceError: $ is not defined
本文介绍了Chrome扩展未捕获的ReferenceError:$未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图制作一个使用jQuery的外部JavaScript文件的Chrome扩展。但我一直在收到这个愚蠢的错误。
任何帮助表示感谢!
$ b 弹出.js
$(document).ready(function(){
$ .ajax({ url:http://www.google.com,success:function(result){
$(#report-details)。html(result);
}});
});
popup.html
<!doctype html>
< html>
< head>
< title> TEST< / title>
< script src =popup.js>< / script>
< script src ='。/ js / jquery.min.js'>< / script>
< script src ='。/ js / jquery.js'>< / script>
< / head>
< body>
< h1> TEST< / h1>
< div id =report-details>
< / div>
< / body>
< / html>
manifest.json
{
manifest_version:2,
名称:我的分机,
说明:有趣的分机,
version:1.0,
browser_action:{
default_icon:icon.png,
default_popup:popup.html
$ bpermissions:[
activeTab
],
content_scripts:[
{
matches:[ http:// * / *,https:// * / *],
js:[js / jquery.min.js]
}
]
}
非常感谢任何帮助。
(我很抱歉,如果这是一个noob错误)
解决方案
第一次加载 Jquery插件在你加载你的popup.js之后,你可以加载你的popup.js文件。
< script src ='。/ js / jquery.min.js'> < /脚本>
< script src =popup.js>< / script>
注意:不需要加载2个jQuery插件
I am trying to make a chrome extension that uses an external javascript file that uses jQuery. But I keep getting this silly error.
Screenshot of error in chrome inspector.
Any help is appreciated thanks!
popup.js
$(document).ready(function() {
$.ajax({url: "http://www.google.com", success: function(result) {
$("#report-details").html(result);
}});
});
popup.html
<!doctype html>
<html>
<head>
<title>TEST</title>
<script src="popup.js"></script>
<script src='./js/jquery.min.js'></script>
<script src='./js/jquery.js'></script>
</head>
<body>
<h1>TEST</h1>
<div id="report-details">
</div>
</body>
</html>
manifest.json
{
"manifest_version": 2,
"name": "my ext",
"description": "fun ext",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [
"activeTab"
],
"content_scripts": [
{
"matches": ["http://*/*","https://*/*"],
"js": ["js/jquery.min.js"]
}
]
}
Any help is greatly appreciated. (I apologize if this is a noob mistake)
解决方案
First Load Jquery Plugin after you can load your popup.js
<script src='./js/jquery.min.js'></script>
<script src="popup.js"></script>
Note: No need to load 2 jquery Plugin
这篇关于Chrome扩展未捕获的ReferenceError:$未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文