Hiermenus Go Forth, XXV - DHTML Lab | 2 | WebReference

Hiermenus Go Forth, XXV - DHTML Lab | 2


Logo

Hiermenus Go Forth, XXV:
Version 4.1.3 - The Complete Script (Full-Window)



HM Without HM

In Version 4.1.1, we introduced an onunload handler for IE5+ users that helped overcome the memory leak problem. It looked like this:

if(HM_IE) {
    HM_f_OtherOnUnload = (window.onunload) ? window.onunload :  new Function;
    window.onunload = function(){
        HM_CurrentMenu = null;
        HM_CurrentItem = null;
        HM_CurrentTree.treeParent = null;
        HM_CurrentTree.startChild = null;
        var Eclength = HM_a_ElementsCreated.length;
        for(var i=Eclength-1; i>=0; i--){
            TempElement = HM_a_ElementsCreated[i];
            TempElement.parentMenu = null;
            TempElement.parentItem = null;
            TempElement.itemElement = null;
            TempElement.currentItem = null;
            TempElement.child = null;
            TempElement.siblingBelow = null;
            TempElement.imgLyr = null;
        }
        TempElement = null;
    
        for(var i=0; i<HM_TotalTrees; i++) {
            HM_a_TopMenus[i].tree.startChild = null;
            HM_a_TopMenus[i].tree.treeParent = null;
        }
        HM_f_OtherOnUnload();
    }
}

These two lines:

        HM_CurrentTree.treeParent = null;
        HM_CurrentTree.startChild = null;

presuppose that HM_CurrentTree is an object. This is always the case, of course, if there is at least one menu tree on your page. If there are no menus, then HM_CurrentTree is null, its initial declared value.

Therefore, if you load HM in your page and chose to NOT create any menus, then an error will be generated when you leave the page and the onunload handler is called.

Remember the error occurs only when HM is invoked and no menus are created. This could be because there are no menu arrays defined, the array file is not loaded or the HM_a_TreesToBuild parameter is an empty array ( [] ).

Hopefully this is a rare occurrence. You should not load HM unless you are planning to have menus on your page. In a test scenario, however, I can see how this could happen.

It happened to Claus Stenkjaer, who alerted us to the problem and the solution:

if(HM_IE) {
    HM_f_OtherOnUnload = (window.onunload) ? window.onunload :  new Function;
    window.onunload = function(){
        HM_CurrentMenu = null;
        HM_CurrentItem = null;
//4.1.3
        if(HM_CurrentTree != null) {
            HM_CurrentTree.treeParent = null;
            HM_CurrentTree.startChild = null;
        }

        ...
    }
}

We check the value of HM_CurrentTree, and if it is null, we skip the two statements.

Files Changed in Version 4.1.3

You will need to overwrite previous versions of the above files to upgrade to 4.1.3. Use the new HM_Loader.js only if you are using the centering function and your page(s) have a !DOCTYPE and no in-line content. A small adjustment was made to account for the new HM_IEcanvas variable.



On the next page, the sample page included in the download.


Produced by Peter Belesis and

All Rights Reserved. Legal Notices.
Created: November 13, 2001
Revised: November 13, 2001

URL: http://www.webreference.com/dhtml/column61/10.html