According to this guide I tried to load JQuery to my Firefox extension.
var Myext = {
loadJQuery: function(wnd) {
var loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
loader.loadSubScript("chrome://myext/content/jquery-1.7.2.min.js", wnd);
var jQuery = wnd.jQuery.noConflict(true);
try {
loader.loadSubScript("chrome://myext/content/jquery.hoverIntent.js", jQuery);
catch (Except) {
alert(Except.toString());
}
return jQuery;
},
onLoad: function(e) {
Myext.jQuery = Myext.loadJQuery(window);
},
showDialog: function(e) {
var $ = Myext.jQuery;
/* JQuery code */
}
}
window.addEventListener("load", function(e) { Myext.onLoad(e); }, false);
window.addEventListener("DOMContentLoaded", function(e) { Myext.showDialog(e); }, false);
Loader has a problem to load jquery.hoverIntent.js
. I downloaded it here
error message: "Type Error: $ is undefined"
In order to use .dialog()
you need to include jQuery UI library also. Put the next line right after you loaded the jQuery library:
loader.loadSubScript("chrome://myext/content/jquery-ui-1.8.18.custom.min.js", wnd);
The last jQuery UI library you can download from here.
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