I would like to include jQuery in a Firefox extension.
I add the following line of code to import the jQuery file:
Components.utils.import("resource://js/jquery.js", window.content.document);
Firefox runs the file immediately after importing. The jQuery file looks like this with an anonymous closures:
(function( window, undefined ) {
...bunch of code....
_jQuery = window.jQuery,
})(window);
When the extension runs there is an error "window is not defined". What is a way to give jQuery access to the window?
Write this to your *.xul file to include jQuery.
<script type="application/x-javascript" src="toolbar.js"></script>
Not tested, but on normal websites, jQuery is loaded into the context of window
. Therefore, you have to use window.content
as scope:
Components.utils.import("resource://js/jquery.js", window.content);
window.content.document
does not contain a property window
.
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