开发者

document.readyState in Firefox 3.5.x

开发者 https://www.devze.com 2023-01-30 06:04 出处:网络
I\'ve a site where I\'ve putten this code to avoid errors: $(function() { var fnDocumentReady = function() {

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 simila开发者_Python百科r??

Thanks!


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
});
0

精彩评论

暂无评论...
验证码 换一张
取 消