Jump to content


  • Posts

  • Joined

  • Last visited

wiggout's Achievements


Newbie (1/7)



  1. Thanks! It is working now. I also had to set "path=/".
  2. Thanks for responding. I broke it down into the functions you described. It still works the same, but it makes more sense the way you broke it down. Anyways, it is still not functioning the way I would like it to. Each main nav is also a link. I don't want it to change the state of the menu until after it has gone to the new page. It sets the cookie and loads the page, but the subnav does not expand until I either click that main nav again or I click on a different main nav. Thanks again for your help. Body: <body id="body" onload="loadMenuConfiguration()"> Main nav: <li class="nav" onmouseover="mOvr1(this);" onmouseout="mOut1(this);" onclick="saveMenuConfiguration('sectionLinks_1'); mClk2(this);"> <a href="/Security-Cameras-s/13.htm" onclick="return false;">Security Cameras</a></li> <ul id="sectionLinks_1" style="display:none; cursor: pointer;"> Javascript: function mClk2(src, popup) {if (!popup) {window.location=src.getElementsByTagName('A')[0].getAttribute('href');} else {window.open(src);} } function setCookie(targetId){ var section="sectionLinks_"; for(var i=1;i<=4;i++) { if((section+i) == targetId){document.cookie=section+i+"=block";} else{document.cookie=section+i+"=none";} }}function getCookie(targetId){ var i,x,y,ARRcookies=document.cookie.split(";"); for (i=0;i<ARRcookies.length;i++) { x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("=")); y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1); x=x.replace(/^\s+|\s+$/g,""); if (x==targetId) { return unescape(y); } }}function openBranch(targetId){ document.getElementById(targetId).style.display="block";}function closeBranch(targetId){ document.getElementById(targetId).style.display="none";}function saveMenuConfiguration(targetId){ setCookie(targetId);}function loadMenuConfiguration(){ var section="sectionLinks_"; for(var i=1;i<=4;i++) { menuState = getCookie(section+i); if(menuState == "block"){openBranch(section+i);} else{closeBranch(section+i);} }}
  3. I am trying to save the state of a tree menu by storing the name of the open section in a cookie, and then reading the cookie onload. It seems to be going to the href url before writing to the cookie. Below is my code and some examples of where the functions are used in my page. Thanks in advance for you help. <body id="body" onload="getMenuState()"> <a href="/" onclick="setMenuState('none');">Home</a> <li class="nav" onmouseover="mOvr1(this);" onmouseout="mOut1(this);" onclick="setMenuState('sectionLinks_1')"> <a href="/Security-Camera-Systems-s/19.htm" >Security Cameras</a></li> function setMenuState(targetId){ for(var i=1;i<=4;i++) {document.getElementById('sectionLinks_'+i).style.display="none";} {document.cookie="openMenu="+targetId;}}function getMenuState(){ var search = "openMenu="; if (document.cookie.length > 0) { offset = document.cookie.indexOf(search) // if cookie exists if (offset != -1) { offset += search.length // set index of beginning of value end = document.cookie.indexOf(";", offset); // set index of end of cookie value if (end == -1){end = document.cookie.length;} value = unescape(document.cookie.substring(offset, end)); if(value != "none"){document.getElementById(value).style.display="block";} } }}
  • Create New...