How can I use jQuery 1.5.2+ in a Firefox addon?

First, I created a function that received a parameter and returned jQuery, for example:

function getjQuery(window)
{
   /*jquery code*/(window);
   return window.jQuery;
}

But then I received the email form, and I was told that I need to use the jQuery file with the original file name and be completely unmodified.

I started looking for an alternative and found this solution , but it does not work.

A jQuery object is being created, but I cannot find any elements. $("#id").lengthalways 0. With the previous method, it was always found.

My current code (which is not working)

AddonNameSpace.jQueryAux = jQuery;

AddonNameSpace.$ = function(selector,context) { 
    return                                                 // correct window
        new AddonNameSpace.jQueryAux.fn.init(selector,context||contentWindow); 
};
AddonNameSpace.$.fn =
    AddonNameSpace.$.prototype = AddonNameSpace.jQueryAux.fn;
AddonNameSpace.jQuery = AddonNameSpace.$;

The jQuery file is loading on top of my overlay browser.xul:

<script type="text/javascript" src="chrome://addon/content/bin/jquery-1.5.2.min.js" />

Am I uploading to the right place?

How can I use jQuery to change the content on a page (HTML) with the jQuery source file, is this possible?

+5
2

e.originalTarget.defaultView jquery.. jQuery, window.document, window.document xul.

gBrowser.addEventListener("DOMContentLoaded", function (e) {
    $("#id", e.originalTarget.defaultView).length
}, true);

$("#id").length;

, , script xul, MozIJSSubScriptLoader.

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

, jquery , , .

+3

: mozIJSSubScriptLoader, . , , jQuery , $("#id").hide() ( .xul).

xpi.

+2

All Articles