Red_CurlyC035.gif (995 bytes) Solve Script Conflicts

Using More Than One Script Per Page


You are here:


The way to go about solving a common conflict that arises when you add more than one JavaScript to a page, and they have the same event handlers trying to do different things is simple, though not quite the same to explain.

Essentially, you want is to end up with only ONE delta for both scripts, with that delta calling the two scripts. Let's list some possible scenarios now, and their resolutions:

 

EXAMPLE #1:
SCRIPT 1: <body onload="dothis()">
SCRIPT 2: <body onload="dothat()">
RESOLUTION: <body onload="dothis();dothat()">


EXAMPLE #2:
SCRIPT 1: <body onload="dothis()">
SCRIPT 2: window.onload=dothat()
RESOLUTION: <body onload="dothis();dothat()">


EXAMPLE #3:
SCRIPT 1: window.onload=dothis
SCRIPT 2: window.onload=dothat
RESOLUTION: <body onload="dothis();dothat()">


As you can see, regardless of whether the two scripts contain "delta" or "beta", the resolution is the same -- remove BOTH lines, and call the scripts directly within the <body> tag, each separated by a semicolon. If you wish to combine three scripts, the procedure is exactly the same.

Using the above technique, both scripts are called and executed, instead of just one -- or neither. 

Related information