Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery in Firefox extension

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?

like image 732
Alexis Avatar asked Nov 09 '10 18:11

Alexis


2 Answers

Write this to your *.xul file to include jQuery.

<script type="application/x-javascript" src="toolbar.js"></script>
like image 69
Yashwant Kumar Sahu Avatar answered Sep 16 '22 14:09

Yashwant Kumar Sahu


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.

like image 32
Felix Kling Avatar answered Sep 20 '22 14:09

Felix Kling