Found this online. Works great:
For the Set Cookie function name and value are mandatory, the rest are optional. I don't use any of them
function getCookie( name ) {
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}
function setCookie( name, value, expires, path, domain, secure ) {
var today = new Date();
today.setTime( today.getTime() );
if ( expires ) {
expires = expires * 1000 * 60 * 60 * 24 * 60;
}
var expires_date = new Date( today.getTime() + (expires) );
document.cookie = name+"="+escape( value ) +
( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}
When I set a menu to show or hide, I save a cookie with it's ID and it's state, open or close. setCookie(myMenu, true or false)
I then created a function that reads all the possible cookie values in when the page is loaded and processes them. I hard coded all the value for the possible menus, but I will go back sometime and find a way to iterate through all the cookie vales and clean up the code. Pseudo code follows:
If objID==null then call function to open menu (A cookie hasn't been set for this value before)
If objID=='true' then call function to open menu
else
call menu function to close menu
Note the quotes around true, the save cookie function saves a string, not a boolean. (much hair pulling on that one!)
Quick easy and flawless.
Now the only problem I have is that FF renders the page, and then processes the cookie. So what happens is the page is shown all menus open, and then it closes the ones that need to be closed. I would love to find a way for it to do all that menu processing and then display the page as it is meant to be seen. Any ideas?
--
Eleipher, The Warlock Extraordinaire
The New BeginningThorium Brother Hood
Guild Webmaster