I am trying to make an extension that gets an XMLrequest and takes the information and writes it to the browser action popup’s html page. Is this possible?
Here’s my manifest file
//manifest.json
"name":"myExtension",
"version":"1.0",
"manifest_version": 2,
"browser_action": {
"default_icon":"favicon.ico",
"default_popup": "popup.html"
}
My browser action popup html file:
<!--popup.html-->
<!DOCTYPE html>
<html>
<head>
<title>My Title</title>
<script src="popup.js"></script>
<script src="jquery.min.js"></script>
</head>
<body>
<p>Hello</p>
<p class="add"></p>
</body>
</html>
And my script:
//popup.js
//Code up to this point gets xml info, I didn't include
var info = //string from xml request
$.(".add").html(info);
I see the Hello paragraph in the popup window, but never the info which should be in the add paragraph, and when I check the console, it tells me that the $ is undefined. How can I get jquery to work for me? I’m a relative newcomer to this so I’m sorry if this is really simple and I don’t understand it.
There are a few points that are wrong
The order of adding your scripts; it should be:
Your selector is wrong; it shouldn’t be
$.(".add")but$(".add"):You need to wrap your jQuery commands into DOM ready/on load:
Also, you don’t need to add the script to
content_scriptsif you don’t going to use it there.You have full access to your extensions resources from the background page and the popup.