jQuery未在Google Chrome扩展程序中定义

时间:2016-05-28 09:46:20

标签: javascript jquery google-chrome referenceerror

我试图在我的Chrome扩展程序中运行jQuery,但我一直收到错误

  

未捕获的ReferenceError:$未定义

我试图在content_script.js中使用jQuery,但它似乎只在background.js中加载

我需要向background.js添加一些额外的代码,以便content_script.js可以使用jQuery吗?

我的代码

的manifest.json

{
"name": "Flip That Tab",

"description": "Flips a guitar tab on ultimate guitar",

"version": "1.0",

"author": "TyDyeTV",

"short_name": "Tab Flip",

"icons": { 
    "16":"img/guitar16.png", 
    "48":"img/guitar48.png", 
    "128":"img/guitar128.png" 
        },

"permissions": [
"activeTab"
],

"background": {
  "scripts": ["jquery-2.2.4.min.js", "background.js"],
  "persistent": false
            },

"browser_action": {
  "default_title": "Flip That Tab",
  "default_icon": "img/guitar.png"
                },

"manifest_version": 2

}

background.js

// Called when the user clicks on the browser action.
chrome.browserAction.onClicked.addListener(function(tab) {

chrome.tabs.executeScript(null, {file: "jquery-2.2.4.min"});
chrome.tabs.executeScript(null, {file: "content_script.js"});

});

content_script.js

// Code to flip tab

function isMusicLine(line)
{
    var numDash = 0;
    for (i=0; i < line.length; i++) 
    {
        if(line[i] == '-') 
        {
            numDash += 1;
        }
    }
    if (numDash > 10)
    {
        return true;
    }
    else
    {
        return false;
    }   
}


function createMusic(line, myArray, tempArr)
{
    if(tempArr.length > 0)
    {
        for (i=0; i< tempArr.length; i++)
        {
            myArray.push(tempArr[i]);
        }
    }
    else
    {
        myArray.push(line);
    }

    return myArray
}



var element = document.getElementById("cont").innerHTML;
var element = $("cont").text(finalDoc)

0 个答案:

没有答案