Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.