View Full Version : turning off persist state on index page?

06-17-2008, 09:52 PM
Hi I need help with the scripting of my menu, I found a switch menu script that does everything I want except if a user chooses the "home" link I want the persist state to stop and the menu to reload with all submenu items closed, I am not a javascript programmer and have looked thru tutorials and such but not sure I'm searching for the right term or function, or how to write a proper conditional statement:confused:...possibly its the cookie manipulation? I wanted to edit the title of my post to cookie manipulation but it won't let me....help anyone?
Here's the code I'm using:

var persistmenu="yes"
var persisttype="sitewide"

if (document.getElementById){
document.write('<style type="text/css">\n')
document.write('.submenu{display: none;}\n')

function SwitchMenu(obj){
var el = document.getElementById(obj);
var ar = document.getElementById("masterdiv").getElementsByTagName("span");

if(el.style.display != "block"){
for (var i=0; i<ar.length; i++){
if (ar[i].className=="submenu")
ar[i].style.display = "none";
el.style.display = "block";
el.style.display = "none";

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!="")

function savemenustate(){
var inc=1, blockid=""
while (document.getElementById("sub"+inc)){
if (document.getElementById("sub"+inc).style.display=="block"){
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid

if (window.addEventListener)
window.addEventListener("load", onloadfunction, false)
else if (window.attachEvent)
window.attachEvent("onload", onloadfunction)
else if (document.getElementById)

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

seems like there should be some little snippet I'm not finding that says if page is "index.php" window.reload or something, because if you just reload the window the persist is still keeping the submenu open....guidance would be greatly appreciated.
thanks in advance