Results 1 to 3 of 3

Thread: Leaving more than one menu open on Switch Menu with cookie

  1. #1
    Join Date
    Apr 2005
    Location
    Ottawa, Ontario, Canada
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Leaving more than one menu open on Switch Menu with cookie

    Script: DD Switch Menu
    http://www.dynamicdrive.com/dynamici...switchmenu.htm

    Hi, I hope you can help me out with this and I am explaining it correctly.. I am using the DD Switch Menu, but I would like to be able to click on a menu, it drops down. Then I click on another one and it drops down while the other one stays open...and so on for the rest of the menus. If you click on a menu that is already open just that one closes. Now I figured that out buy just putting in this code below:

    var persistmenu="yes" //"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 (document.getElementById){ //DynamicDrive.com change
    document.write('<style type="text/css">\n')
    document.write('.submenu{display: none;}\n')
    document.write('</style>\n')
    }

    function SwitchMenu(obj){
    if(document.getElementById){
    var el = document.getElementById(obj);
    var ar = document.getElementById("masterdiv").getElementsByTagName("span"); //DynamicDrive.com change
    if(el.style.display != "block"){ //DynamicDrive.com change

    el.style.display = "block";
    }else{
    el.style.display = "none";
    }
    }
    }

    </script>


    BUT Now there is no cookie set...so if I go to another page and then go back to that page all of them are closed again. I want the ones I have left dropped down to still be in that state upon going back to that page.

    Thanks for any help!

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Add this after your code but, before the closing </script> tag:
    Code:
    function get_cookie(Name) { 
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { 
    offset += search.length
    end = document.cookie.indexOf(";", offset);
    if (end == -1) end = document.cookie.length;
    returnvalue=unescape(document.cookie.substring(offset, end))
    }
    }
    return returnvalue;
    }
    
    function onloadfunction(){
    if (persistmenu=="yes"){
    var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
    var cookievalue=get_cookie(cookiename)
    if (cookievalue!="")
    if (cookievalue!="[]"){
    openids=new Array()
    openids=eval(cookievalue)
    for (i = 0; i < openids.length; i++){
    if (openids[i]!==undefined)
    document.getElementById(openids[i]).style.display="block"
    }
    }
    }
    }
    
    function savemenustate(){
    var inc=1, blockid="["
    while (document.getElementById("sub"+inc)){
    if (document.getElementById("sub"+inc).style.display=="block")//{
    blockid+="'sub"+inc+"',"
    //break
    //}
    inc++
    }
    blockid+="]"
    var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
    var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
    document.cookie=cookiename+"="+cookievalue
    }
    
    if (window.addEventListener)
    window.addEventListener("load", onloadfunction, false)
    else if (window.attachEvent)
    window.attachEvent("onload", onloadfunction)
    else if (document.getElementById)
    window.onload=onloadfunction
    
    if (persistmenu=="yes" && document.getElementById)
    window.onunload=savemenustate
    Last edited by jscheuer1; 04-25-2005 at 08:36 AM. Reason: Mozilla Compatibility
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Apr 2005
    Location
    Ottawa, Ontario, Canada
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Dude you rock! Thank you so much you made my life easier..hehe

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •