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:
<script src="jquery.js"></script>
<script src="popup.js"></script>
Your selector is wrong; it shouldn't be $.(".add")
but $(".add")
:
$(".add").html(info);
You need to wrap your jQuery commands into DOM ready/on load:
$(function() {
var info = //string from xml request
$(".add").html(info);
});
Also, you don't need to add the script to content_scripts
if you don't going to use it there.
You have full access to your extensions resources from the background page and the popup.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With