1

I've a site where I've putten this code to avoid errors:

$(function() {
  var fnDocumentReady = function() {
    if(document.readyState != "complete") {
      setTimeout(function () { fnDocumentReady(); }, 300);
      return;
    }

    //do stuff
  };

  fnDocumentReady();
});

But I've recently discovered that in FF 3.5 does not execute the code where the "do stuff" is. After analyzing and debbuging I realized that document.readySate in FF is always undefined. Is there any way to replace this for something else that works similar??

Thanks!

Diego
  • 16,436
  • 26
  • 84
  • 136

1 Answers1

1

To answer the why? part: document.readyState was added in Firefox 3.6.


There's no need here for the extra check, jQuery already abstracts detecting when the DOM is ready, all you need is:

$(function() {
  //do stuff
});

If you're wanting all the images loaded before your code runs, just use window.onload instead, like this:

$(window).load(function() {
  //do stuff
});
Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
  • It might stand to reason that this is not a good answer because not everybody uses jQuery, but as it was accepted I can't complain too much. I will say that in Firefox, if your code runs early enough, it can listen to the "DOMContentLoaded" event to figure out when Firefox 3.6 and later would have returned `readyState == 'complete'` – Guss Sep 04 '11 at 14:06
  • @Guss - While true, this doesn't address all (especially older) browsers...and the context of the question was all about jQuery :) – Nick Craver Sep 04 '11 at 14:28