Page 1 of 1

window.onload... I have been wondering...

Posted: Tue Oct 31, 2006 12:37 pm
by Luke
Every time I attempt to apply a function to window.onload... it seems to not work. It always fails. I think the reason is because the window is loaded before a lot of the things I'm trying to work with...

such as this...

Code: Select all

	function addEvent(obj, evType, fn){ 
	 if (obj.addEventListener){ 
	   obj.addEventListener(evType, fn, false); 
	   return true; 
	 } else if (obj.attachEvent){ 
	   var r = obj.attachEvent("on"+evType, fn); 
	   return r; 
	 } else { 
	   return false; 
	 } 
	}
        addEvent(window, 'load', showLetter('A', 'show_category'));
'show_category' is a div that is supposed to be populated with html when the window loads... but that div isn't available at the time the window loads I guess... so what should I be using if not window.onload?

Posted: Tue Oct 31, 2006 3:07 pm
by Weirdan
I guess it should be:

Code: Select all

addEvent(window, 'load', function() { 
   showLetter('A', 'show_category'); 
});

Posted: Tue Oct 31, 2006 3:27 pm
by Luke
:oops: That worked... thanks.