无法在Chrome扩展程序中使用JQuery(Not able to use JQuery in Chrome Extensions)

编程入门 行业动态 更新时间:2024-10-27 10:26:11
无法在Chrome扩展程序中使用JQuery(Not able to use JQuery in Chrome Extensions)

我有一个Google Chrome扩展程序,其中我有一个background.js,我正在尝试使用JQuery。

获得以下错误。

Uncaught ReferenceError: $ is not defined

我的清单文件代码部分

"content_scripts": [ { "matches": ["<all_urls>"], "js": ["script.js", "jquery.js","front.js"] } ], "web_accessible_resources": ["https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"], "content_security_policy": "script-src 'self' https://ajax.googleapis.com; object-src 'self'",

我无法获得在此扩展中使用JQuery函数的任何线索。 如果您需要更多理由,请告诉我。

编辑#1:清单文件

{ "name": "Tool", "description": "Extension", "manifest_version": 2, "version": "5.0.0.0", "manifest_version": 2, "background": { "scripts": ["background.js"] }, "permissions": [ "tabs", "http://*/*", "https://*/*", "storage" ], "options_page": "options.html", "icons":{"16": "images/F_icon_16x16.png", "48": "images/F_icon_48x48.png", "128": "images/F_icon_128x128.png"}, "content_scripts": [ { "matches": ["<all_urls>"], "js": ["jquery.js", "script.js", "front.js"] } ], "content_security_policy": "script-src 'self' ; object-src 'self'", "browser_action": { "default_title": "Tool", "default_icon": "images/F_icon.png" } }

I have a Google Chrome Extension in which I have a background.js and I am trying to use JQuery in it.

Getting following error.

Uncaught ReferenceError: $ is not defined

My manifest File code part

"content_scripts": [ { "matches": ["<all_urls>"], "js": ["script.js", "jquery.js","front.js"] } ], "web_accessible_resources": ["https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"], "content_security_policy": "script-src 'self' https://ajax.googleapis.com; object-src 'self'",

I am not able to get any clue of using JQuery functions in this extension. Please let me know if you need more justification.

Edit#1: Manifest File

{ "name": "Tool", "description": "Extension", "manifest_version": 2, "version": "5.0.0.0", "manifest_version": 2, "background": { "scripts": ["background.js"] }, "permissions": [ "tabs", "http://*/*", "https://*/*", "storage" ], "options_page": "options.html", "icons":{"16": "images/F_icon_16x16.png", "48": "images/F_icon_48x48.png", "128": "images/F_icon_128x128.png"}, "content_scripts": [ { "matches": ["<all_urls>"], "js": ["jquery.js", "script.js", "front.js"] } ], "content_security_policy": "script-src 'self' ; object-src 'self'", "browser_action": { "default_title": "Tool", "default_icon": "images/F_icon.png" } }

最满意答案

改变这一部分:

"js": ["script.js", "jquery.js","front.js"]

对此:

"js": ["jquery.js","script.js","front.js"]

该行的顺序是包含文件的顺序。 所以你首先需要jquery.js来定义$(用于jquery),然后用你的脚本来定义其他脚本......

change this part:

"js": ["script.js", "jquery.js","front.js"]

to this:

"js": ["jquery.js","script.js","front.js"]

The order of that line is the order the files are included. so you need first the jquery.js to define the $ (for jquery) and then the other scripts with your scripting...

更多推荐

本文发布于:2023-08-02 18:56:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1380621.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:程序   Chrome   Extensions   JQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!