#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Location
    Utah
    Posts
    1
    Rep Power
    0

    Exclamation


    Maybe not a god, but here goes....

    I'm working on a new design using HeirMenus for navigation. The script calls 2 external .js files that hold the array and the menu configuration. Now, as most designers know, you can't use an onload event in 2 different places on a page, they conflict and one won't work. OK- so I have the heir menus and a DHTML text scroller that need loaded. However, the Heir menus don't use a standard window.onload or body onload to call the script. The script uses this: (cut and paste from FAQ regarding this subject)


    "The HM onload handler, as we know, calls the startIt() function:

    loader.onload = startIt;

    We must, therefore, make sure that one onload handler calls both startIt() and startTheOtherTechnique()! Many, if not most, DHTML techniques using an onload handler, begin a dynamic display when the page has loaded. Our fader, and Doc JavaScript's scroller, are two examples. The HM script, on the other hand, does not begin a technique, it simply creates more elements on the page. It, in essence, extends the load procedure and, consequently, should take precedence.

    This means that the other script's onload handler should be cut from the page, and pasted into the end of the HM load function:

    function startIt() {
    isLoaded = true;
    if (isFrames) {
    menuLoc = eval("parent.frames." + mainFrName);
    if (NS4) {
    loader.captureEvents(Event.LOAD);
    loader.onload = NSloaded;
    menuLoc.onunload = NSunloaded;
    }
    if (IE4) {
    menuLoc.document.body.onunload = IEunloaded;
    }
    }
    else {
    menuLoc = window;
    }
    menuLoc.nav = nav = window;
    if (clickKill) {
    if (NS4) menuLoc.document.captureEvents(Event.MOUSEDOWN);
    menuLoc.document.onmousedown = clicked;
    }
    makeTop();

    startTheOtherTechnique(arg1,arg2,...,argn); <-- paste here at end of startIt()
    }
    Now, the menus will be created, your page elements will be complete, and then your other technique will begin, with no conflict."


    Sure! Sounds easy enough! Just slap it on in there! Too bad I can't get it to work! I'm not exactly an expert with Javascript, so I'm not sure how to add this to the code:


    window.onload=startscroll


    It's the last line in the script for the scroller...

    Can someone PLEASE tell me how to do this! I've been pulling my hair out for 2 days on this one! Here's the page if you want to see the whole code:

    http://cyberjohnsons.com/index3.shtml

    Thanks in advance!!!

    Doug
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Posts
    81
    Rep Power
    14
    I think you have a couple of options that should work pretty easily without resorting to trying to append your function call inside the other function, but you can do that too (see Method 3).

    Method 1:
    I assume that the onload handler is being set directly inside the included .js file. What you can do is simply write your own onload handler and have it call the other ones. For example, in pseudocode:

    // include file 1, assuming it sets onload=includeload1
    // include file 2, assuming it sets onload=includeload2

    function myLoad()
    {
    includeload1();
    includeload2();
    }
    window.onload = myLoad;

    Method 2:
    In the body tag it is possible specify multiple function calls separated by semicolons. Just place the needed calls here. Example:
    <BODY onload="includeload1();includeload2()"

    Method 3:
    The most foolproof way to avoid clobbering other developers onload is to look for it and dynamically create a new function that calls it and yours. Example:

    if (window.onload)
    {
    var loadStr = window.onload.toString();
    var newLoadStr = loadStr.substring(loadStr.indexOf("{") + 1,newLoadStr.lastIndexOf("}") - 1) + "\r" + ";" + "myOnLoad()";
    window.onload = new Function(newLoadStr);
    }
    else
    window.onload = myOnLoad;

    Hope that helps
    - Bob


IMN logo majestic logo threadwatch logo seochat tools logo