document.addEventListener("DOMContentLoaded", function() {
alert('dom is ready ^-^');
});
<script>
(function(){var DomReady = window.DomReady = {};var userAgent = navigator.userAgent.toLowerCase();var browser = {version: (userAgent.match( /.+(?:rv|it|ra|ie)[/: ]([d.]+)/ ) || [])[1],safari: /webkit/.test(userAgent),opera: /opera/.test(userAgent),msie: (/msie/.test(userAgent)) && (!/opera/.test( userAgent )),mozilla: (/mozilla/.test(userAgent)) && (!/(compatible|webkit)/.test(userAgent))};var readyBound = false;var isReady = false;var readyList = [];function domReady() {if(!isReady) {isReady = true;if(readyList) {for(var fn = 0; fn < readyList.length; fn++) {readyList[fn].call(window, []);}readyList = [];}}};function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') {window.onload = func; } else {window.onload = function() { if (oldonload) {oldonload(); } func();} }};function bindReady() {if(readyBound) {return;}readyBound = true;if (document.addEventListener && !browser.opera) {document.addEventListener("DOMContentLoaded", domReady, false);}if (browser.msie && window == top) (function(){if (isReady) return;try {document.documentElement.doScroll("left");} catch(error) {setTimeout(arguments.callee, 0);return;}domReady();})();if(browser.opera) {document.addEventListener( "DOMContentLoaded", function () {if (isReady) return;for (var i = 0; i < document.styleSheets.length; i++)if (document.styleSheets[i].disabled) {setTimeout( arguments.callee, 0 );return;}domReady();}, false);}if(browser.safari) {var numStyles;(function(){if (isReady) return;if (document.readyState != "loaded" && document.readyState != "complete") {setTimeout( arguments.callee, 0 );return;}if (numStyles === undefined) {var links = document.getElementsByTagName("link");for (var i=0; i < links.length; i++) {if(links[i].getAttribute('rel') == 'stylesheet') {numStyles++;}}var styles = document.getElementsByTagName("style");numStyles += styles.length;}if (document.styleSheets.length != numStyles) {setTimeout( arguments.callee, 0 );return;}domReady();})();}addLoadEvent(domReady);};DomReady.ready = function(fn, args) {bindReady();if (isReady) {fn.call(window, []);} else {readyList.push( function() { return fn.call(window, []); } );}};bindReady();})();
</script>
<script>
DomReady.ready(function() {alert('dom is ready ^-^');});
</script>
(function(funcName, baseObj) {
funcName = funcName || "docReady";
baseObj = baseObj || window;
var readyList = [];
var readyFired = false;
var readyEventHandlersInstalled = false;
function ready() {
if (!readyFired) {
readyFired = true;
for (var i = 0; i < readyList.length; i++) {
readyList[i].fn.call(window, readyList[i].ctx);
}
readyList = [];
}
}
function readyStateChange() {
if ( document.readyState === "complete" ) {
ready();
}
}
baseObj[funcName] = function(callback, context) {
if (typeof callback !== "function") {
throw new TypeError("callback for docReady(fn) must be a function");
}
if (readyFired) {
setTimeout(function() {callback(context);}, 1);
return;
} else {
readyList.push({fn: callback, ctx: context});
}
if (document.readyState === "complete") {
setTimeout(ready, 1);
} else if (!readyEventHandlersInstalled) {
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", ready, false);
window.addEventListener("load", ready, false);
} else {
document.attachEvent("onreadystatechange", readyStateChange);
window.attachEvent("onload", ready);
}
readyEventHandlersInstalled = true;
}
}
})("docReady", window);