0

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">
Oleksandr IY
  • 2,783
  • 6
  • 32
  • 53

2 Answers2

2

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.

Community
  • 1
  • 1
Mike C
  • 3,077
  • 22
  • 29
1

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

James Hibbard
  • 16,490
  • 14
  • 62
  • 74