Alexis
Alexis

Reputation: 25163

Using jQuery extension in Firefox extension

I have a Firefox extension that uses coda-slider to move between photos. Coda-slider requires that jQuery be available. Is there a way to include jQuery, after the page has loaded, in the DOM of the page so that after it is inserted it is loaded?

Upvotes: 2

Views: 852

Answers (3)

swmcdonnell
swmcdonnell

Reputation: 1421

Using the subscript loader component works great. The only disadvantage is that you have to include jQuery as a local resource (either in chrome or as a module). For example:

var loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
             .getService(Components.interfaces.mozIJSSubScriptLoader);
loader.loadSubScript("chrome://myext/content/jquery-1.5.2.min.js");

https://developer.mozilla.org/en/mozIJSSubScriptLoader

Upvotes: 2

Chinmayee G
Chinmayee G

Reputation: 8117

You can use jQuerify plugin for firefox. It is also available for chrome also but not sure

Upvotes: 0

David Thomas
David Thomas

Reputation: 253308

Assuming that your extension can use JavaScript:

var s=document.createElement('script');
s.setAttribute('src','https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js');
// or whatever other url you want to get jQuery from.
document.getElementsByTagName('body')[0].appendChild(s);

Source for this snippet: Learning jQuery.

Upvotes: 4

Related Questions