Results 1 to 3 of 3

Thread: General Info question on two scripts on one page

  1. #1
    Join Date
    Feb 2006
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default General Info question on two scripts on one page

    Not asking for help per rules. Just some infomration on what to look for

    This is the question. I ran one script. Works fine.

    I ran script two. Works fine

    I put the two together and nothing. A conflict.

    Both scripts use onload to run.

    However if I change one script to onclick and leave the other as onload

    As soon as I load the page, the first script runs and when I click anywhere, with the mouse, the second script runs fine.

    So they both work fine in conjunction with one and other. Both run at the same time.

    I realize that if you run two scripts sometimes you run into double names for event handlers and variables and functions. But if the scripts will work together with an onload and onclick, does this mean that that would be ruled out.

    Again I am just curious about this? Seems to me if there was a conflict between the scripts they shouldn't work together at all.

    Thanks for your help. You guys are great

  2. #2
    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

    Well, there are conflicts and there are conflicts. An interesting test you devised there for your two scripts and yes, as you describe it, it does demonstrate that the two particular scripts you used could work together if only they didn't conflict in grabbing the onload event of the page.

    How to resolve this? It depends upon how each script is accessing the onload event of the page and also upon how you want to combine these two events into one.

    The easiest way, if the two scripts cooperate, is to remove and/or move each scripts onload event to the body tag or leave it there and add to it if it is already there, say one is coded into the script like so:

    Code:
    window.onload=fillup
    and the other already uses the body tag's onload event:

    HTML Code:
    <body onload="goForIt();">
    These two could be combined in the body tag like so:

    HTML Code:
    <body onload="goForIt();fillup();">
    The important thing to notice is that when coded in the script, an onload function call will look like so:

    fillup

    or

    fillup;

    But when placed in the body onload event must be made like so:

    fillup();

    More information is found following the tutorial in the sticky below:
    Note: Questions regarding multiple script usage are not usually replied to due to their time consuming nature. See this thread for more information, and this tutorial for one possible solution.
    - John
    ________________________

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

  3. #3
    Join Date
    Feb 2006
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Once again it works perfectly.

    It took awhile to get it. I found it was easier to start over and cut and paste in sections. But it makes really good sense.

    The links were great too.

    Thank you for your help

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
  •