Scroll To Top

Enter a query to search our site. Note that you can use "*" and "?" as wildcards. Enclosing more than one word in double quotes ("CSS Layout") will search for the exact phrase.

PVII Knowledge Base

1. Select a product ...
2. Select category ...
3. Search the Knowledge Base...

Question #291

In Tree Menu Magic 2 (TMM2) is there a way to have an external page link open the menu to a specific section? perhaps by using an anchor?

The Answer

Prepared Feb. 2010 by Gerry Jacobsen, PVII

You can have the Tree Menu Magic 2 (TMM2) system automatically open to a specific link or section by adding an anchor to the page link, the anchor would be the text of the link in the menu on the target page to match.

For example, to automatically open to the "Articles" section of the menu on another page, you would add "#Articles" to the page address,

myPage.htm.#Articles

and then when this page opens the TMM2 system will automatically open the the menu item whose link text matches the anchor, "Articles".

This will require a quick add-on tweak to the TMM2 scripts file, here's how:

1. Open the p7TMMscripts.js file and scroll to the end of the page. Add a new blank line and then copy and paste this new function into that new line:

function P7_TMManchor(el){
   var i,h,an,tA,pp,a,im;
   h=document.location.hash;
   if(h){
     an=h.substring(1,h.length);
     tA=el.getElementsByTagName('A');
     for(i=0;i<tA.length;i++){;
        if(an==tA[i].firstChild.nodeValue){
            pp=tA[i].parentNode;
               while(pp){
                    if(pp.tagName&&pp.tagName=='LI'){
                         P7_TMMsetClass(pp,'li_current_mark');
                         a=pp.getElementsByTagName('A');
                         if(a&&a[0]){
                               P7_TMMsetClass(a[0],'current_mark');
                               if(a[0].hasImg){
                                    im=a[0].getElementsByTagName('IMG')[0];
                                    im.mark=true;
                                    im.src=im.p7imgswap[3];
                                }
                                if(a[0].tmmsub){
                                    P7_TMMopen(a[0],1);
                                }
                          }
                    }
                    else{
                        if(pp==el){
                              break;
                        }
                    }
                    pp=pp.parentNode;
                 }
             }
         }
     }
 }
  

2. Locate the last 5 lines of the P7_TMMinit() function, around line 209:

         }
      }
   }
   p7TMMa=true;
 }

3. Create a new line just after the first }, and copy and paste this code into that new line:

         }
         P7_TMManchor(tM);
      }
   }
   p7TMMa=true;
 }

4. Save and close the file.

That's it, the TMM2 system will now automatically open and current mark the menu to the menu item whose text matches the anchor in the page address.

So, if the link reads like this:

http://www.MyNewSite.com/myPage.htm#Articles

then the page would open with the Articles menu section open.

Back to the questions list