Created
January 13, 2011 21:49
-
-
Save anonymous/778685 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function domReady(callback) { | |
var domLoaded; | |
var called; | |
var onReadyStateChange = function () { | |
if (document.readyState == 'complete') { | |
domLoaded(); | |
} | |
}; | |
var interval; | |
var pollForReady = function () { | |
try { | |
document.documentElement.doScroll('left'); | |
domLoaded(); | |
} | |
catch(e) {} | |
}; | |
if (window.addEventListener) { | |
domLoaded = function() { | |
if (!called) { | |
called = true; | |
callback(); | |
} | |
window.removeEventListener('DOMContentLoaded', domLoaded, false); | |
window.removeEventListener('load', domLoaded, false); | |
}; | |
window.addEventListener('DOMContentLoaded', domLoaded, false); | |
window.addEventListener('load', domLoaded, false); | |
} else if (window.attachEvent) { | |
interval = window.setInterval(pollForReady, 13); | |
domLoaded = function() { | |
if (!called) { | |
called = true; | |
callback(); | |
} | |
window.clearInterval(interval); | |
window.detachEvent('onreadystatechange', onReadyStateChange); | |
window.detachEvent('onload', domLoaded); | |
}; | |
window.attachEvent('onreadystatechange', onReadyStateChange); | |
window.attachEvent('onload', domLoaded); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment