NoFunc Javascript onLoad

May 12th, 2009

The jQuery document ready function is very nice, but for some applications it takes to long to trigger. On those occasions, I've started using the nofunc onload script:

function $(v) { return(document.getElementById(v)); }
function init() { $('example').innerHTML=(time()-loadTime)+'ms'; }
function time() { return(new Date().getTime()); }
function quick() {
    if(!$('example')) {
        if(time()-loadTime<=5000) setTimeout("quick()",50);
        else window.onload=init;
    else init();

var loadTime=time();

I'm using it with the PHP image replacement script, but with gdofcgi as the back-end. To keep it compatible with jQuery I had to make some changes, but I think its an excellent replacement. You can view the changes I made here in the mt.js file.
Yearly Indexes: 2003 2004 2006 2007 2008 2009 2010 2011 2012 2013 2015 2019 2020