We are often asked: Why is it that when you use 1 script on a page with an "onLoad" tag event it works correctly, but if you add a secondary event code ... it can often turn to errors.
The way to go about solving conflicts of having dual "<body="onLoad 2 events"> is very simple. Essentially, what you want is to end up with is ... you only want ONE onLoad= initiate command for both onLoad script call tags.
Here's a list of some possible scenarios, and their correction format:
EXAMPLE #1:
SCRIPT 1: <body onLoad="dothis()">
SCRIPT 2: <body onLoad="dothat()">
Correct Format: <body onLoad="dothis();dothat()">
EXAMPLE #2:
SCRIPT 1: <body onLoad="dothis()">
SCRIPT 2: window.onLoad=dothat()
Correct Format: <body onLoad="dothis();dothat()">
EXAMPLE #3:
SCRIPT 1: window.onLoad=dothis
SCRIPT 2: window.onLoad=dothat
Correct Format: <body onLoad="dothis();dothat()">
As you can see, regardless of whether the two scripts contain "this event" or "that event", the formatting is the same for each event type. The 2 lines call the scripts directly within the <body> tag for each to initiate separated only by a
semicolon " ; " in between each onLoad event needed.
If you wish to combine three or more scripts, the procedure is the exact same
process. Separate each event by using a s emicolon " ; " between each
needed onLoad event tag.
EXAMPLE #4:
SCRIPT 1: <body onLoad="dothis()">
SCRIPT 2: <body onLoad="dothat()">
SCRIPT 3: <body onLoad="dothird()">
Correct Format: <body onLoad="dothis();dothat();dothird()">
By using the above technique, both or all onLoad scripts are called and executed in order, as opposed to just one, or none. If you use this type of formatting in your code, you should have multiple
onLoad events that operate error free.
This same format holds true for onUnload events as well.
|