Welcome to WebmasterWorld Guest from 54.196.232.162

Forum Moderators: brotherhood of lan & mack

Message Too Old, No Replies

combining onload events

     
9:29 pm on Mar 28, 2003 (gmt 0)

New User

10+ Year Member

joined:Mar 5, 2003
posts:38
votes: 0


I want to combine two onload event in the body tag: A random image onload event and a preload onload event. However, I get a script error. Here is the code:

onload="rotateImage('rImage')" onLoad="MM_preloadImages('images/bar_r1_c1_f2.gif','images/bar_r2_c1_f3.gif','images/bar_r3_c1_f4.gif','images/bar_r4_c1_f5.gif','images/bar_r5_c1_f6.gif');"

Can anyone help me?

9:33 pm on Mar 28, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:May 26, 2000
posts:37301
votes: 0


Instead of using two onLoad event handlers, hook the two functions together with a semicolon:

onload="rotateImage();MM_preloadImages();"

1:19 am on Apr 11, 2003 (gmt 0)

Preferred Member

10+ Year Member

joined:Apr 25, 2002
posts:470
votes: 0


Or (as I usually recommend) to save on ugly code bloat, put both function calls into a container function, and put it all in an external javascript, so instead of :

<body onload="rotateImage('rImage')" onLoad="MM_preloadImages('images/bar_r1_c1_f2.gif','images/bar_r2_c1_f3.gif','images/bar_r3_c1_f4.gif','images/bar_r4_c1_f5.gif','images/bar_r5_c1_f6.gif');">

you end up with

<body onload="loadpage();">