--- jquery.js 2007-10-13 17:52:14.000000000 +0200 +++ jquery-test.js 2007-10-13 19:41:10.000000000 +0200 @@ -2169,27 +2169,48 @@ if ( jQuery.browser.mozilla || jQuery.browser.opera ) // Use the handy event callback document.addEventListener( "DOMContentLoaded", jQuery.ready, false ); - - // If Safari or IE is used - else { - // Continually check to see if the document is ready - function timer(){ + + // If IE is used + else if ( jQuery.browser.msie ) { + // Use the trick described by Diego Perini + // http://javascript.nwbox.com/IEContentLoaded/ + (function () { try { - // If IE is used, use the trick by Diego Perini - // http://javascript.nwbox.com/IEContentLoaded/ - if ( jQuery.browser.msie || document.readyState != "loaded" && document.readyState != "complete" ) - document.documentElement.doScroll("left"); - - // and execute any waiting functions - jQuery.ready(); + // throws errors until after ondocumentready + document.documentElement.doScroll("left"); } catch( error ) { - setTimeout( timer, 0 ); + setTimeout( arguments.callee, 10 ); + return; } - } - - timer(); + // no errors, execute any waiting functions + jQuery.ready(); + })(); + // always fire before onload + document.onreadystatechange = function() { + if (document.readyState == "complete") { + document.onreadystatechange = null; + jQuery.ready(); + } + }; } + // If Safari is used + else if ( jQuery.browser.safari ) + // Continually check to see if the document.readyState is valid + jQuery.safariTimer = setInterval(function(){ + // loaded and complete are both valid states + if ( document.readyState == "loaded" || + document.readyState == "complete" ) { + + // If either one are found, remove the timer + clearInterval( jQuery.safariTimer ); + jQuery.safariTimer = null; + + // and execute any waiting functions + jQuery.ready(); + } + }, 10); + // A fallback to window.onload, that will always work jQuery.event.add( window, "load", jQuery.ready ); }