PDA

View Full Version : Two javascripts confilct



Ricardo FSA
12-09-2009, 11:29 PM
Hello!

I'm using A (http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm) javacript to load html into div's. Evertyhing was working great until i added another java script B (http://www.dynamicdrive.com/dynamicindex2/cmarquee2.htm) to have scrolling text inside a div.

The index page uses A script to load a html file that has B script inside.

Everything works fine but the problem is that the div with the scrolling funtion from script B does not scroll down, it only shows the text.

I have searched for conflicts between javascripts but didn't succeed in aplying the solution's to my problem.

I've read something like <body onload= and add the two functions of both scripts. The probem is that i dont know what to write in the onload=, and in wich page should i add the body onload=

I think the function from B script is initializemarquee, but not sure. But i don't know what is the function i should write from script A.

Is there another solution to this? Something you could recomend me, short and simple?

Thanks in advance!!

djr33
12-10-2009, 04:07 AM
For questions relating to dynamic drive scripts, post them here:
http://www.dynamicdrive.com/forums/forumdisplay.php?f=2
(I have no moved this thread.)

Also, this type of question-- for problems getting two scripts to work on a single page-- support will be limited because it can be very difficult to work out all the possible conflicts.

In general, there are two reasons scripts conflict:
1. Variable (or function) names overlap. Just find them and change the names. Simple.
2. Some process conflicts with having two operations: for example, an onmouseover command on a single area makes two different scripts occur at the same time (and confuses things).

If your problem is actually just getting the body tag to work (it may or may not be, and once this is fixed you may find more conflicts), then what you do is this:
1. Take the body tag from script a. Make sure it has a ; at the end.
2. Cut/paste whatever the body tag from script b has after the ;.
That should be all you need to do.
This will look something like <body onload="scripta(); scriptb();">

jscheuer1
12-10-2009, 08:47 AM
Scripts in AJAX loaded content don't run. Use an iframe or find a way to initialize the imported content after it is loaded. If you want more help:

Please post a link to the page on your site that contains the problematic code so we can check it out.

djr33
12-10-2009, 09:09 AM
Or just include the script on the main page so that any included pages (via ajax) will run with it. The main page will then have two scripts on it (but one won't be used), and when you load a page that happens to have the script on it, then it will run, because the script will be preloaded that way.

This will be easy to do if you just want one script to work like this (if you can predict what the included pages will have on them). If you want the page to support any possible loaded page (with any possible scripts on it), then you can't possibly predict all possible scripts, so an iframe approach would be better.