Results 1 to 3 of 3

Thread: persistent cookies

  1. #1
    Join Date
    Jul 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default persistent cookies

    I love this script http://www.dynamicdrive.com/dynamicindex1/navigate2.htm

    the only problem is that I would like it to remember the setting (open/close) even when user closes IE (persisten cookies instead of session cookies).

    Is there an easy way to modify this script? Please note I'm really rookie.

    thanks a lot
    jiri

  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

    Replace these two functions:

    Code:
    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
    }
    
    function do_onload(){
    uniqueidn=window.location.pathname+"firsttimeload"
    getElementbyClass("switchcontent")
    if (enablepersist=="on" && typeof ccollect!="undefined"){
    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()
    }
    }
    With these:

    Code:
    function saveswitchstate(){
    var inc=0, selectedItem=""
    while (ccollect[inc]){
    if (ccollect[inc].style.display=="block")
    selectedItem+=ccollect[inc].id+"|"
    inc++
    }
    var date = new Date();
    date.setTime(date.getTime()+(10*86400000));
    var expires = "; expires="+date.toGMTString();
    document.cookie=window.location.pathname+"="+selectedItem+expires;
    }
    
    function do_onload(){
    uniqueidn=window.location.pathname+"firsttimeload"
    getElementbyClass("switchcontent")
    if (enablepersist=="on" && typeof ccollect!="undefined"){
    var date = new Date();
    date.setTime(date.getTime()+(10*86400000));
    var expires = "; expires="+date.toGMTString();
    document.cookie=(get_cookie(uniqueidn)==""? uniqueidn+"=1" : uniqueidn+"=0")+expires;
    firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
    if (!firsttimeload)
    revivecontent()
    }
    Notice the two red 10's in the above new functions. These set the two cookies (the script already required two cookies) for 10 days. Increase or decrease as desired. Both values should be set to the same number though.
    - John
    ________________________

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

  3. #3
    Join Date
    Jul 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks a lot John !! This is exactly what I need.

    I also changed the calls little bit so the cookie is not set only when you leave the page, but onClick as well.

    thanks again
    jiri

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
  •