Results 1 to 4 of 4

Thread: Two javascripts confilct

  1. #1
    Join Date
    Dec 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Two javascripts confilct

    Hello!

    I'm using A javacript to load html into div's. Evertyhing was working great until i added another java script B 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!!

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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();">
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •