![]() |
Solving
Javascript Conflicts |
|
How to Place more than one javascript on a webpageIt's a common problem. You have one javascript on your page that works fine. You add another javascript and one, or both, stop working. Most
javascript conflicts of this type are caused by both scripts using the All javascripts have a function, they are designed to do a particular action on a webpage such as shake text or wiggle something. The javascript writer then has to call the function later in the script to make the function work, this function is usually called when the webpage has loaded. Let's give an example of the problem first and then an example of the solution. Script
#1 has the onload function that goes directly into the body tag like so Script #2 has the
onload function within the script itself like so; You can see that both scripts want to use the onload function, who wins, normally the one in the body tag. Now
the good news. If you combine both functions within the body tag you will erase
the conflict. Here's the example from the 2 scripts above; Remember to remove the window.onload=delay from script#2 and both scripts should now work. Conflict solved! What if you have more than 2 scripts? Same solution! What if you have 2 or more scripts with the window.onload function? Remove that line from within each script and combine each onload function into the body tag as in the first example. Happy Javascripting.
|
|