gekido
07-01-2005, 10:34 PM
Hello everyone,
Been using dynamic drive scripts for years, love them - best resource on the net...
Anyways, I've recently decided to use the 'switch content' state script for a new site in development.
I'm basically using the switch content script as a sidebar outlook style menu across the entire site...works great on all browsers etc...
However what I would like to do is get the script to remember whether the user has visited the site previously...
(script url: http://www.dynamicdrive.com/dynamicindex17/switchcontent.htm)
Yes the script already does this via a cookie, however my site management system is php driven, and as a result the path's for each page end up being unique, in the form http://www.mysite.com/?page=mypage.php
What I am looking to do is have the state remembered across ALL of the sub-pages of the domain, however the script, by default, only remembers the state for the current page that you are visiting.
so if the user visits mysite.com/?page=page1.php and opens/expands any of the side menu options - the second they click on a second link in the menu, it doesn't remember the state any more and contracts the entire side menu...
so the user can open/close any of the submenu options when they are visiting mysite.com/?page=page1.php, but then when they click a link (potentially to mysite.com/?page=page2.php) the menu closes and they end up having to reopen the menu options etc...
I've tried tweaking the javascript for the cookie handler so that it doesn't save or use the pathname when saving the cookie, but this hasn't fixed it...
eg:
function getselectedItem(){
//if (get_cookie(window.location.pathname) != ""){
//selectedItem=get_cookie(window.location.pathname)
if (get_cookie(window.location) != ""){
selectedItem=get_cookie(window.location)
return selectedItem
}
else
return ""
}
function saveswitchstate(){
var inc=0, selectedItem=""
while (ccollect[inc]){
if (ccollect[inc].style.display=="block")
selectedItem+=ccollect[inc].id+"|"
inc++
}
//document.cookie=window.location.pathname+"="+selectedItem
document.cookie=window.location+"="+selectedItem
}
function do_onload(){
//uniqueidn=window.location.pathname+"firsttimeload"
uniqueidn=window.location+"firsttimeload"
var alltags=document.all? document.all : document.getElementsByTagName("*")
ccollect=getElementbyClass(alltags, "switchcontent")
statecollect=getElementbyClass(alltags, "showstate")
if (enablepersist=="on" && ccollect.length>0){
document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0"
firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
if (!firsttimeload)
revivecontent()
}
if (ccollect.length>0 && statecollect.length>0)
revivestatus()
}
note that this isn't the entire javascript, but you can see where i've commented the changed lines to remove the .pathname entries...
anyone know how i would get this script to save the expanded/contracted states for ALL of the pages on the single domain/site? basically the entire site system is template driven and essentially 'includes' the content for each individual page within the template.
simple, but it works. if i can get the cookies to save the state across all of the pages, it would be ideal...
thanx in advance,
mike w
gdgi
Been using dynamic drive scripts for years, love them - best resource on the net...
Anyways, I've recently decided to use the 'switch content' state script for a new site in development.
I'm basically using the switch content script as a sidebar outlook style menu across the entire site...works great on all browsers etc...
However what I would like to do is get the script to remember whether the user has visited the site previously...
(script url: http://www.dynamicdrive.com/dynamicindex17/switchcontent.htm)
Yes the script already does this via a cookie, however my site management system is php driven, and as a result the path's for each page end up being unique, in the form http://www.mysite.com/?page=mypage.php
What I am looking to do is have the state remembered across ALL of the sub-pages of the domain, however the script, by default, only remembers the state for the current page that you are visiting.
so if the user visits mysite.com/?page=page1.php and opens/expands any of the side menu options - the second they click on a second link in the menu, it doesn't remember the state any more and contracts the entire side menu...
so the user can open/close any of the submenu options when they are visiting mysite.com/?page=page1.php, but then when they click a link (potentially to mysite.com/?page=page2.php) the menu closes and they end up having to reopen the menu options etc...
I've tried tweaking the javascript for the cookie handler so that it doesn't save or use the pathname when saving the cookie, but this hasn't fixed it...
eg:
function getselectedItem(){
//if (get_cookie(window.location.pathname) != ""){
//selectedItem=get_cookie(window.location.pathname)
if (get_cookie(window.location) != ""){
selectedItem=get_cookie(window.location)
return selectedItem
}
else
return ""
}
function saveswitchstate(){
var inc=0, selectedItem=""
while (ccollect[inc]){
if (ccollect[inc].style.display=="block")
selectedItem+=ccollect[inc].id+"|"
inc++
}
//document.cookie=window.location.pathname+"="+selectedItem
document.cookie=window.location+"="+selectedItem
}
function do_onload(){
//uniqueidn=window.location.pathname+"firsttimeload"
uniqueidn=window.location+"firsttimeload"
var alltags=document.all? document.all : document.getElementsByTagName("*")
ccollect=getElementbyClass(alltags, "switchcontent")
statecollect=getElementbyClass(alltags, "showstate")
if (enablepersist=="on" && ccollect.length>0){
document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0"
firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
if (!firsttimeload)
revivecontent()
}
if (ccollect.length>0 && statecollect.length>0)
revivestatus()
}
note that this isn't the entire javascript, but you can see where i've commented the changed lines to remove the .pathname entries...
anyone know how i would get this script to save the expanded/contracted states for ALL of the pages on the single domain/site? basically the entire site system is template driven and essentially 'includes' the content for each individual page within the template.
simple, but it works. if i can get the cookies to save the state across all of the pages, it would be ideal...
thanx in advance,
mike w
gdgi