logo

Solving Javascript Conflicts
How to place more than one javasript on webpage

Google
Web Search Hypergurl.com



Handy Tip : Sometimes the javascript conflict will not be the codes fault but a complete browser compatability question. For example the new IE 7.0 browser does not support status bar scripts no matter what the writer tries to do to overcome the problem.

Bookmark This Page

How to Place more than one javascript on a webpage

It'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
<onload> function. There is an easy work around that will solve the conflict. The solution is to combine both onload functions together.

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
<body onload="shake ()">

Script #2 has the onload function within the script itself like so;
window.onload=Delay;

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;
<body onload="shake (); Delay()">

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.

 
 
Hypergurl Hosting
IMPROVED PLANS
FREE Domain Name
web hosting and domain registration

 
Hosting Log In
Username:
Password: Sign up

 

NEW!
Blog for Webmasters

web site design feed Website Design

 

 
Refer A Friend
Your Email
Your Name
Friends Email
Friends Name





Home
Site Map
Email Hypergurl
About
Link To Hypergurl

Site design copyright 2001-2006 © hypergurl.com