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

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

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

Post 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?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

I guess it should be:

Code: Select all

addEvent(window, 'load', function() { 
   showLetter('A', 'show_category'); 
});
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

:oops: That worked... thanks.
Post Reply