PDA

View Full Version : 2 java scripts on one page



bavarian
11-21-2005, 09:15 AM
i am trying to make use of 2 java scripts, loaded in one page

the first one is the Switch Content Script (http://www.dynamicdrive.com/dynamicindex17/switchcontent.htm) and it worked fine for me, the way i configured it.

the second one is the Tab Content Script (http://www.dynamicdrive.com/dynamicindex17/tabcontent.htm) and it's there where trouble starts.

this second one will not work before i disable the first one. my questions are if both can be run at the same time? if any modifications need to be made, since both scripts contain functions with identical names? or anything else to consider?

thanks in advance !

jscheuer1
11-21-2005, 09:36 AM
Functions with identical names. Yep, you have to change one of the scripts. You can just do a global search and replace on one of them, replacing the identical function name with a new unique one. Say the function is:


function findedge(){
code here
}

Just find and replace all instances of 'findedge' in one of the scripts with 'findedge1'.

Yeppers again, there are other things to consider. If both scripts do something onload, either in their code or via an onload attribute in the body tag, these events must be combined:

.

I'm also going to include my standard 'spiel' on this:

Aside from the tutorial from the above, which usually is the solution when the problem is two different scripts, you may need to consult:

http://www.howtocreate.co.uk/tutorials/index.php?tut=0&part=0&TOshow=allshow#refcon

Which explains how two scripts on the same page may not use the same set of variable names, id names, etc. This is especially important if the problem is two copies of the same script on a page but, can come into play with two different scripts when the first step won't fix it.

One other approach that works in both situations, if adaptable to one (or more) of the scripts, is to put one script in a borderless iframe. It will look like it is on the same page but, since it really is on a separate page, conflicts are no longer an issue.