DOMReady - The Pro Way

March 19th, 2008   Filed Under Javascript, Tips & Tricks, browser, gyan, jQuery, snippet  

I was just digging through the concept of DOMReady used in jquery and found it to be very complicated. Then I started looking for some alternatives. I found the following code from Stuart Colville http://muffinresearch.co.uk :

function DOMReady(f){//THANKS TO STUART COLVILLE[http://muffinresearch.co.uk]
if (/(?!.*?compatible|.*?webkit)^mozilla|opera/i.test(navigator.userAgent)){ // FEELING DIRTY YET?
document.addEventListener("DOMContentLoaded", f, false);
}else{
window.setTimeout(f,0);
}

I am really feeling lucky to have such a concise and foolproof code. I should say its the pro way.
Thought to share with everybody. But one request I have to make that please don’t forget to specify his name and web address while using his code. We should be loyal to each other on the web community to help each other and get recognized for whatever we do.


Comments

Leave a Reply