Javascript 无法在google chrome扩展中使用jquery

Javascript 无法在google chrome扩展中使用jquery,javascript,jquery,google-chrome-extension,Javascript,Jquery,Google Chrome Extension,我正在尝试使用jquery进行一次后ajax调用,我已经尝试了几乎所有的解决方案,但似乎都不起作用。我的舱单是: {"name": "__MSG_extName__", "version": "0.1", "manifest_version": 2, "description": "__MSG_extDesc__", "icons": {"16": "icon16.png", "128": "icon128.png"}, "background": {"persistent": false, "

我正在尝试使用jquery进行一次后ajax调用,我已经尝试了几乎所有的解决方案,但似乎都不起作用。我的舱单是:

{"name": "__MSG_extName__",
"version": "0.1",
"manifest_version": 2,
"description": "__MSG_extDesc__",
"icons": {"16": "icon16.png", "128": "icon128.png"},
"background": {"persistent": false, "scripts": ["background.js"]},
"default_locale": "en",
"content_scripts": [
{
  "matches": ["<all_urls>"],
  "js": ["jquery-2.1.3.js"]
}
],
"permissions": ["contextMenus", "downloads", "downloads.open", "tabs", "http://*/*", "https://*/*"]}
我得到的错误是:

Download Link is http://www.mymp3song.com/files/download/id/33724
background.js:14 jquery is loaded
extensions::uncaught_exception_handler:8 Error in response to tabs.executeScript: ReferenceError: $ is not defined
at Object.callback (chrome-extension://kbhkaajolcelehoonafmkgaahfgphnok/background.js:22:2)
at chrome-extension://kbhkaajolcelehoonafmkgaahfgphnok/background.js:13:16

如您所见,我以编程方式和在清单中添加了jquery.js,但似乎都不起作用。即使我移除其中任何一个,它也不起作用。有人能告诉我应该怎么做才能让它工作吗?

把你的json修改成这个,它就可以为你工作了 参考是


如果希望jQuery在后台页面中运行,则需要将其添加到后台页面

您尝试使用的两种方法都是将代码添加到内容脚本上下文中

您需要的是:

"background": {
  "persistent": false,
  "scripts": ["jquery-2.1.3.js", "background.js"]
},
在后台页面中加载jQuery。请注意,顺序很重要


我建议大家看一下。

我会稍微修改一下这个答案,以适应您正在使用的jquery的任何版本:
“content\u scripts”:[{“js”:[“[jquery FILE NAME HERE],“background.js”],“matches”:[“http://*/*”,“https://*/*”]}]
我使用的是jquery 1.8.3版,我只使用背景脚本,因此添加内容脚本可能不是个好主意。不管怎么说,我照你说的做了,但没用。是的,我在看你的答案之前就想好了,然后就要发帖了。无论如何谢谢你!
"content_scripts": [ {
    "js": [ "jquery.min.js", "background.js" ],
    "matches": [ "http://*/*", "https://*/*"]
  }] 
"background": {
  "persistent": false,
  "scripts": ["jquery-2.1.3.js", "background.js"]
},