2012-12-04 133 views
4

我有一个谷歌浏览器扩展程序,其中有一个background.js,我正在尝试在其中使用JQuery。无法在Chrome扩展中使用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" 
    } 
} 

回答

5

改变这一部分:

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

这样:

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

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

+0

仍然会出现相同的错误 –

+1

@SaurabhSaxena如果你删除这行然后??? ''“web_accessible_resources”:[“https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js”],' – Mathlight

+0

仍然是相同的错误 –