Oleksandr IY
Oleksandr IY

Reputation: 3146

Jquery is not defined in firefox

I am getting Jquery is not defined in FireFox browser but works in opera, here is ex http://eef.percipio.me/index/charts.

I load jquery with

if (!window.jQuery) {
  var jq = document.createElement('script'); jq.type = 'text/javascript';
  // Path to jquery.js file, eg. Google hosted version
  jq.src = 'http://eef.percipio.me/themes/third_party/charts/js/jquery-1.10.2.min.js';
  document.getElementsByTagName('head')[0].appendChild(jq);
}

and seems problem with this code, since it works if I do

<script src="http://eef.percipio.me/themes/third_party/charts/js/jquery-1.10.2.min.js" type="text/javascript">

Upvotes: 0

Views: 101

Answers (2)

James Hibbard
James Hibbard

Reputation: 17795

Works intermittently for me, too. Definitely a timing issue.

You could poll for the availability of jQuery:

function withjQuery ($) {
  // use $
} 
function pollForjQuery () {
  if (window.jQuery) {
    withjQuery(window.jQuery);
  } else {
    // checks for jQuery again in 50ms
    setTimeout(pollForjQuery, 50);
  }
}

// check for jQuery in 0, 50, 100, 150, 200ms etc.
pollForjQuery();

Reference

Upvotes: 1

Mike C
Mike C

Reputation: 3117

Your link is working intermittently for me, even with firebug open. It looks like a timing issue to me, I think you need to make sure jQuery is loaded before trying to use it.

Try googling 'load jquery if not loaded' or take a look at this article - it provides code that should help you.

Also, here is another SO question about a similar issue.

Upvotes: 2

Related Questions