DHTML Lab: HierMenus CENTRAL: Version 3.x FAQ #3 - dhtmlab.com | WebReference

DHTML Lab: HierMenus CENTRAL: Version 3.x FAQ #3 - dhtmlab.com

Frequently Asked Question #3

Entered: Feb 15, 1999


I am using the menu script and the fader script (or any other DHTML script). If placed alone in the page, the scripts works fine. When both are included in the same page, only one of the two works, depending on their page order. That is, the first script doesn't kick in. Why?

or

I included your menu script in my page but it doesn't work. Must be a problem with your code, cause all the other scripts in the page work!

The Hierarchical Menus script uses the onload event handler of the window/frame in which they appear. You may have already set the onload handler in another script. If this is the case, then the one referenced last will be the active one. That is, if the window's onload handler is redefined after the HM script, the menu handler will not be invoked and the menus will not be created.

The HM are a fairly lengthy and complicated script. It is best to avoid too many other techniques on the same page.

If, however, the other instance of the onload handler is important, the onload handlers should be combined into one:

Example:

You have a second onload event handler defined somewhere in your page, which calls a function named startTheOtherTechnique(). This handler may be defined in one of the following ways:

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.


Produced by Peter Belesis and

All Rights Reserved. Legal Notices.
Created: Dec 29, 1998
Revised: June 26, 2001

URL: https://www.webreference.com/dhtml/hiermenus/version3/faq/faq3.html

Justtechjobs.comFind a programming school near you






Online Campus Both