mrmartineau
8/26/2015 - 11:40 AM

Better DOMready

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
	}
};