javascript - How to use jQuery in Firefox Extension -


I want to use jQuery inside a Firefox extension, I have imported the library into a Axle file like this:

& lt; Script type = "app / x-javascript" src = "chrome: //myExtension/content/jquery.js" & gt; & Lt; / Script & gt;

But the $ () function is not recognized in the Axl file, nor jQuery ().

I made a mistake about the problem and found some solutions but none worked with me:

I referred to the 'content.document' object (which refers to the 'document' object Tries to pass) the jQuery function in the form of a reference parameter:

  $ ('img', content.document);  

But still it is not working, does any problem arise from this?

I use the following example.xul :

  & lt ;? XML version = "1.0"? & Gt; & Lt; Overlay id = "example" xmlns = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" & gt; & Lt; Top & gt; & Lt; / Head & gt; & Lt; Script type = "app / x-javascript" src = "jquery.js" & gt; & Lt; / Script & gt; & Lt; Script type = "application / x-javascript" src = "example.js" & gt; & Lt; / Script & gt; & Lt; / Overlay & gt;  

And here is a example.js

  (function () {jQuery.noConflict (); $ = function ( Selector, context) {new jQuery.fn.init (selector, reference || example.doc);} $ $ .fn = $ .prototype = jQuery.fn; example = new function () {}; example.log = function () (Firebug.Console.logFormatted (logic, blank, "log");}; example.run = function (doc, aEvent) {// Check for website if (! Doc.location.href.match (/ ^ Http: \ / \ / (. *.)? Stackoverflow \ .com (\ /.)) Returns; // if it is already loaded, check (doc.getElementById ("plugin-example ")) Return; // Setup this.win = aEvent.target.defaultView.wrappedJSObject; this.doc = doc; // O World, this.main = main = $ ('div id = "plugin-example" gt;') .appendTo (doc.body) .html ('Example loaded!'); Main.css ({ Background: '#FFF', Color: '# 000', Position: 'Absolute', Top: 0, Left: 0, Pillow Ding: 8}); Main.html (main.html () + '- jQuery & lt ; B & gt; '+ $ .fn.jquery +' & lt; / b & gt; '); }; // bind plugin var delay = function (event) {var doc = aEvent.originalTarget; SetTimeout (function () {example.run (doc, aEvent);}, 1); }; Var load = function () {gBrowser.addEventListener ("DOMContentLoaded", delay, true); }; Window.addEventListener ("Page", Load, False); }) ();  

Comments