简体   繁体   中英

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?

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 .

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM