Skip to content

Instantly share code, notes, and snippets.

@mrmartineau
Created August 26, 2015 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrmartineau/282192a1821694109bb2 to your computer and use it in GitHub Desktop.
Save mrmartineau/282192a1821694109bb2 to your computer and use it in GitHub Desktop.
Better DOMready
// This is needed to prevent onreadystatechange being run twice
var ready = false;
document.onreadystatechange = function() {
if (ready) {
return;
}
// interactive = DOMContentLoaded & complete = window.load
if (document.readyState == 'interactive' || document.readyState == 'complete') {
ready = true;
// init you code here
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment