View Full Version : keeping menu expanded when opening linked page

12-14-2009, 11:13 AM
1) Script Title: Accordion Content script (v1.7.1)

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/ddaccordion.htm

3) Describe problem:
I have a website (building in Dreamweaver CS4). I am not working with frames so each pages contains the menu.
When I click on a menu entry the linked page is opened but then the menu entries are collapsed. I think that this comes because the menu is reloaded when loading the new page.
I need to let the menu stay open so the user can see the next entries in this group and he can see where he is in the menu structure.

Sorry, my English is not so good.
What do can I do? Who can help me?

Best Almute

12-14-2009, 04:21 PM
Use either the persistence (persiststate) feature or the defaultexpanded feature, whichever works best for your situation. Both are explained on the demo page.

12-14-2009, 05:17 PM
"persistence" is set to "true".
I have tested more and found that it works like I need if I start the page new in a browser. The menu stays open in the last stage.
But if I do some more clicks in the menu and go to other pages then after a some time it doesn't work any more. Then the menu collapses every time a new page is shown.

12-14-2009, 07:45 PM
Then perhaps try persistence false (don't quote the word false) and try out the defaultexpanded feature. With it you can set which part of the accordion is open on any given page, and it works every time for that page regardless of where that page gets opened.

12-14-2009, 08:37 PM
I don't have quoted the word true for persistence.
I can't use the defaultexpanded feature because every page uses the same parameters. They are outsourced in a .js file. And the menu is outsourced too in linked files for the script, the css and the menu itself (I will have a lot of pages when all is finished). The menu has nested submenus.
Is this the reason of my problems?

12-15-2009, 02:14 AM
Perhaps. Though not the "reason" per se, more like why you cannot easily use defaultexpanded. Only the init part of the code, which is instructed to be placed on the page anyway, ex (from the demo page):

headerclass: "mypets", //Shared CSS class name of headers group
contentclass: "thepet", //Shared CSS class name of contents group
revealtype: "mouseover", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
collapseprev: true, //Collapse previous content (so only one open at any time)? true/false
defaultexpanded: [0], //index of content(s) open by default [index1, index2, etc]. [] denotes no content.
onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
animatedefault: false, //Should contents open by default be animated into view?
persiststate: false, //persist state of opened contents within browser session?
toggleclass: ["", "openpet"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
togglehtml: ["none", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively ["position", "html1", "html2"] (see docs)
animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
oninit:function(expandedindices){ //custom code to run when headers have initalized
//do nothing
onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
//do nothing

must be unique to each page to allow for a defaultexpanded to be unique to each page.

Perhaps some helper javascript, and/or even server side code (if you have that available) could be setup to select the defaultexpanded on the basis of the address of the page. That way, the init code could probably remain in one file to be used by all pages.

So, do you have a server side language available to you? Also, is there a naming convention for the pages that use this script that could be used to easily determine what the number for defaultexpanded would be based upon each page's name? If not, could one be established?

I could figure most of this stuff (except for what server side language(s), if any are available) out myself if I had a link to the site.

12-15-2009, 03:40 PM
After I have uploaded my new site to a space on the server of my provider I found that many other things that don't work any more. (I tested all on a Mac OS X Server).
Now I need to check all again.
The menu still works the first view clicks and than stops working.

Thank you again for your help


12-16-2009, 10:15 AM
Hi, the website now works – but the menu still stops staying opened after some time.

Please look at our test version (not all entries are linked) at www.secondsign.de



12-16-2009, 12:39 PM
To be honest with you, I can't really tell what's going on. Partly it's the language barrier. Although I had a year of it in high school, I don't read German very well, if that's what that is. But the real problem I think is your choice of activating the Accordion with mouseover. The menu reacts in an unintuitive manner, jumping about seemingly uncontrollably. If I click on an item and don't move the mouse away quickly enough or too quickly, there will be consequences once the next page loads. I think you should change it to a click controlled Accordion. That may solve your other problem as well, if not, I'll have another look at it once it is click controlled.

12-16-2009, 04:06 PM
I have changed to "click" and deleted the links which are on those entries leading to next level. But the error still occurs: The first clicks it works fine and then after some more clicks it stops working. :-(

12-16-2009, 06:44 PM
I've been at it for about 20 minutes, the menu is staying open. What browser are you using? Regardless of the browser though, if it is set to empty cookies periodically, that would cause the problem you are seeing.

Are there any specific steps I can take to see this problem in action?

12-17-2009, 08:54 PM
Hi, I am using Safari on Mac as browser. I tested with Firefox too and had the same problem (and some more others with the other java scripts I am using). Automatic empty cookies in not activated.
What browser do you use?