2

I was creating a firefox extension. and I am including the jquery in the xul file as

    <script type="application/x-javascript" src="libs/project/libs/jquery.js" />

followed by some other files which uses jquery

    <script type="application/x-javascript" src="sample.js" />
    <script type="application/x-javascript" src="sample2.js" />
                     .
                     .
                     .

but here I am getting some errors like

  • ReferenceError: jQuery is not defined

  • TypeError: a is undefined

  • ReferenceError: $ is not defined

what should I do ?

Hrishi
  • 1,424
  • 1
  • 13
  • 29
  • Which script is throwing the errors? – Beetroot-Beetroot Dec 19 '12 at 20:55
  • the sampple1.js and sample2.js (all scripts that uses $ and jQuery) – Hrishi Dec 20 '12 at 04:12
  • 1
    I can think of three possibilities; (1) the path to `jquery.js` is wrong, (2) `type="application/x-javascript"` is not appropriate; (3) something else redefines `jQuery` and `$`. – Beetroot-Beetroot Dec 20 '12 at 04:36
  • (1) I am able to see the jquery.js code by following the link in the error console (2) same thing happens when I use just the script tag without type (3) I added jQuery.noConflict(); $ = function(selector,context) { return new jQuery.fn.init(selector,context||example.doc); }; $.fn = $.prototype = jQuery.fn; now $ is not defined error is not coming , how can i avoid jQuery is not defined error? – Hrishi Dec 20 '12 at 07:46
  • Hrishi, try `$jq = jQuery.noConflict();` immediately after loading "...libs/jquery.js". Then see if `$jq` acts as a reliable alias for `jQuery` in the other scripts. – Beetroot-Beetroot Dec 20 '12 at 08:04
  • The thing is , most of the other scripts are library files which I don't want to touch. :( – Hrishi Dec 20 '12 at 09:10
  • Hrishi, I'm fresh out of ideas. Try searching to see if anyone else has reported the same issue with FF extensions. – Beetroot-Beetroot Dec 20 '12 at 12:58

1 Answers1

2

Possible reason for this is this bug: http://bugs.jquery.com/ticket/12357

JQUERY 1.8.0 NOT PARSEABLE BY XUL RUNNER APPLICATIONS

You can test this by setting up a simple xul runner window and including jQuery, then alert the typeof jQuery or $ which will result in a response of undefined.

If you paste the jQuery code into a script tag in the XUL main window, you will be able to see all the various parsing issues that have been released in this build.

Hrishi
  • 1,424
  • 1
  • 13
  • 29