Two Onload Functions, But how?

  • Thread starter ={ Advocated }=
  • Start date
A

={ Advocated }=

Hi there, i need to add to onload functions, well one function to an
existing one..

This is the original one:
<BODY leftMargin=0 topMargin=0
marginwidth="0" marginheight="0"
onload="MM_preloadImages('homeblack.gif','mailblack.gif','bookmarkblack.gif'
)">

And i need to add this:
<body onload="init()">

Cant seem to get it to work though?

Any ideas?

Cheers
 
D

David Dorward

={ Advocated }= said:
Hi there, i need to add to onload functions, well one function to an
existing one..

This is the original one:
<BODY leftMargin=0 topMargin=0
marginwidth="0" marginheight="0"

There are no "leftMargin" topMargin" "marginwidth" or "marginheight"
attributes in HTML. They are badly supported unoffical extensions.

Use: body { margin: 0; padding: 0; } in a style sheet to do this properly.
onload="MM_preloadImages('homeblack.gif','mailblack.gif',
'bookmarkblack.gif' )">

Eugh. Macromedia JavaScript, generally regarded as "yuck".

Here's a nice preloader script:
http://dithered.com/javascript/image_preloader/index.html
And i need to add this:
<body onload="init()">

Cant seem to get it to work though?

You can only have one onload function... but that function can do multiple
things.

onload="preload();init();"

Or, better yet (IMO) move it to an external JavaScript file:

window.onload = function() {
preload();
init();
}
 
S

Steve Pugh

={ Advocated }= said:
Hi there, i need to add to onload functions, well one function to an
existing one..

This is the original one:
<BODY leftMargin=0 topMargin=0
marginwidth="0" marginheight="0"

There's no need at all to use leftmargin and topmargin. The browsers
that support them support the CSS equivalents as well.

marginwidth and marginheight are only needed by NN4. How important is
it to remove the body margins in a browser that probably screws up the
rest of your design anyway? ;-)
onload="MM_preloadImages('homeblack.gif','mailblack.gif','bookmarkblack.gif'
)">

Ah, Macromedia's JS functions. Sigh.
And i need to add this:
<body onload="init()">

Cant seem to get it to work though?

Two ways.

1. Make a function.
onLoad="myFunc()"

and then in your JS:
function myFunc() {

MM_preloadImages('homeblack.gif','mailblack.gif','bookmarkblack.gif');
init();
}

has the advantage of being compact and can be shared between many
pages in an external JS file. Not so useful if, for example, you're
preloading different images on different pages.

2. Directly in the event handler.
onLoad="
MM_preloadImages('homeblack.gif','mailblack.gif','bookmarkblack.gif');init();"

The bit you were missing was the ; between the calls to the two
functions.

Steve
 
M

m

={ Advocated }= said:
Hi there, i need to add to onload functions, well one function to an
existing one..

This is the original one:
<BODY leftMargin=0 topMargin=0
marginwidth="0" marginheight="0"
onload="MM_preloadImages('homeblack.gif','mailblack.gif','bookmarkblack.gif'
)">

And i need to add this:
<body onload="init()">

Cant seem to get it to work though?

Just create a function that calls both the functions
you want to call.

function zot{
MM_preloadImages(......)
init()
}

Then call the zot function from
'onload='

Reread the section on functions in
your JavaScript reference.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,201
Latest member
KourtneyBe

Latest Threads

Top