Created
August 26, 2015 11:40
-
-
Save mrmartineau/282192a1821694109bb2 to your computer and use it in GitHub Desktop.
Better DOMready
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
// 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