dontberude
dontberude

Reputation: 551

JS wont run in extension

Im making a Chrome extension and the java script wont run when I try the extension in chrome but it works fine if i open it in a regular tab.

The only thing that is supposed to happen is that there should be a log in the console and an alert when the button is clicked.

the popup.html file

<html>
<head>
    <title> </title>
</head>
<body>

    <h1>Enter key word</h1>
    <input id="input" type="text">
    <input id ="keyWord" type="submit" value="Hide the thingy"/>

    <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.js"></script>
    <script type="text/javascript" src="extjs.js"></script>

</body>
</html>

The extjs.js file

$(document).ready(function(){

    console.log("sdfsdfsdfsdfs");
    $("#keyWord").click(function(){

        var input = document.getElementById("input");
        console.log(input);
        console.log("sdfsdfsdfsdfs");
        alert("sdfsdfsdf");

    });
});

the manifest.json file

{
  "manifest_version": 2,
  "name": "Hello World!",
  "version": "1.0",
  "description": "Chrome extension",
  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  }
}

Upvotes: 0

Views: 53

Answers (1)

berrberr
berrberr

Reputation: 1960

The problem is that the way you are loading jQuery from the external CDN violates the Content Security Policy. To fix this you can download jquery, place it in the extension directory, and load it with <script type="text/javascript" src="jquery.js"></script>.

Upvotes: 2

Related Questions