View Full Version : collapsing menu when returning to index.htm page

12-03-2006, 06:43 PM
1) Script Title: Switch Menu 1

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex1/switchmenu.htm

3) Describe problem: Is there a way to have the pesitance work as normal but for the menus to collapse when loading a particular page ie the index page?... in essence to lose the persitance on jst that page??


12-03-2006, 07:32 PM
Yes, on that page, set it to no:

From the Demo Page:

<script type="text/javascript">

* Switch Menu script- by Martial B of http://getElementById.com/
* Modified by Dynamic Drive for format & NS4/IE4 compatibility
* Visit http://www.dynamicdrive.com/ for full source code

var persistmenu="no" //"yes" or "no". Make sure each SPAN content contains an incrementing ID starting at 1 (id="sub1", id="sub2", etc)
var persisttype="sitewide" //enter "sitewide" for menu to persist across site, "local" for this page only

If you still want changes made on that page to be reflected on other pages running the script, change this line from the script on that page as well:

if (persistmenu=="yes" && document.getElementById)


if (document.getElementById)

12-04-2006, 06:55 AM
Hi John

Thanks for this and the follow up on the other thread. one question though..

The site uses the external menu.js file to control the actions of the menu. If I make the changes you recomend then would this not mess up the persistance all the pages?...



12-04-2006, 07:25 AM
There is no such external file with this script though, of course, one could be employed and would probably be a good idea if the same menu is used on numerous pages.

There are at least two ways to go in such a situation. You could remove the call to the external file from the one page and put a separate copy of the script, with the desired changes, on that page.

Or, what I would recommend, is to set things up so that different values could be used on the one page but still employing the external file. There are quite a number of ways to do that, here's one. On the external script, all you need are these changes (red):

var persistmenu=typeof isindex=='undefined'? "yes" : "no"; //"yes" or "no". Make sure each SPAN content contains an incrementing ID starting at 1 (id="sub1", id="sub2", etc)


if ((persistmenu=="yes"||typeof isindex!='undefined') && document.getElementById)

Then on your index page have this before the call to the external script:

<script type="text/javascript">
var isindex=1;

12-04-2006, 04:00 PM
Ok thanks,

I'll give it a try..... and let you know


12-08-2006, 03:59 PM

Works like a dream thanks John!