DHTML Lab - dhtmlab.com - Hierarchical Menus Ver. 3 - Addendum VII (v3.07) | 4 | WebReference

DHTML Lab - dhtmlab.com - Hierarchical Menus Ver. 3 - Addendum VII (v3.07) | 4

Logo

Hierarchical Menus Ver. 3 - Addendum VII (v3.07)
two minor fixes for both browsers


The Error

If the wrist and mouse finger actions are fast enough over a menu item, that is, if you continue to click a menu item AND spastically move your mouse on/off the menu item and the associated navigation frame link, you might generate this error:

We have duplicated this behavior in Explorer, but not in Navigator, although there is little reason why it should not affect both browsers.

The Line:1 Char:1 error very rarely refers to the first character in the first line of a script. Rather it refers to a string-that-is-being-evaluated. Browsers store any strings-to-be-evaluated as virtual files. When the time comes for them to be evaluated, the associated virtual file is executed.

Such strings can be found in eval() and timer statements:

eval(string);
setTimeout(string,msecs);
setInterval(string,msecs);

Our particular problem is associated with a timer statement, in the hideTop() function:

function hideTop() {
    whichEl = this;
    (clickKill) ? whichEl.hideSelf() : (this.hideTimer = setTimeout("whichEl.hideSelf()",mSecsVis));
}

Recall that whichEl, in this instance, refers to the top-level menu of a menu tree. The hideSelf() method hides this menu. If we want the top-level menu to be hidden upon a mouseout (clickKill is false), then we assign a setTimeout() to the menu's hideTimer property, and the menu is hidden after the time stored in the mSecsVis variable.

You all remember that, don't you? Good.

Now, there may be an instance when the menu's hideSelf() method does not exist. The menu is still being created, and not all methods have been assigned to it, and the timer still exists from the previous time and the user keeps clicking and moving the mouse out of the menu, setting up a timer, then clicking the menu item and before the page has even unloaded the user has moved over the navigation frame link calling PopUp(), then out of the navigation link, calling popDown(), which calls hideAll(), which sets up hideSelf() again, then popUp() again, then mouses over the menu item, then mouses out, then back over to the navigation link, then out of it again, then clicks the menu item. Try doing the above at the speed of light several times, and you will generate the error.

And maybe you won't.

You will probably have a user who complains, however. It never fails.

We can avoid the error, by making two modifications to the hideTop() function:

function hideTop() {
    whichTop = this;
    (clickKill) ? whichTop.hideSelf() : (this.hideTimer = setTimeout("if(whichTop.hideSelf)whichTop.hideSelf()",mSecsVis));
}