Results 1 to 6 of 6

Thread: Ajax Tabs Content Script (v 2.2) WITH COOKIES?

  1. #1
    Join Date
    Aug 2009
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Arrow Ajax Tabs Content Script (v 2.2) WITH COOKIES?

    1) Script Title: Ajax Tabs Content Script (v 2.2)

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...tent/index.htm

    3) Describe problem:
    I would like to persist the tab settings with a cookie, because when the session is closed my users interfact (with your tabs script) will be reset again.
    Is this possible?

    Or in an other way?

    BTW: thx for this nice script ! :-)

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Try changing the line:

    Code:
    ddajaxtabs.setCookie=function(name, value){
    	document.cookie = name+"="+value+";path=/" //cookie value is domain wide (path=/)
    }
    to:

    Code:
    ddajaxtabs.setCookie=function(name, value){
    	var expirestr="; expires="+expireDate.setDate(new Date().getDate()+5).toGMTString()
    	document.cookie = name+"="+value+";path=/"+expirestr //cookie value is domain wide (path=/)
    }
    This sets the cookie to persist for 5 days.
    DD Admin

  3. #3
    Join Date
    Aug 2009
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by ddadmin View Post
    Try changing the line:

    Code:
    ddajaxtabs.setCookie=function(name, value){
    	document.cookie = name+"="+value+";path=/" //cookie value is domain wide (path=/)
    }
    to:

    Code:
    ddajaxtabs.setCookie=function(name, value){
    	var expirestr="; expires="+expireDate.setDate(new Date().getDate()+5).toGMTString()
    	document.cookie = name+"="+value+";path=/"+expirestr //cookie value is domain wide (path=/)
    }
    This sets the cookie to persist for 5 days.
    wohoo :-)
    thx
    I'll make that 365 days I think so it stays that way.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    For your information, while you can set a long expiration date, the user always has the option to delete a cookie and the system may for some reason remove a cookie such as clearing "private data".
    Due to this, it's not entirely reliable that it will actually last that long, but there's no better way to do that. So just know that it won't always last as long as you say-- think of 365 days as a limit to how long the cookie can be kept, not a rule that it must be. [Technically the user can force the cookie to remain longer by modifying it, but that would mean very specific intent, and knowledge.]

    For the average user, though, that should on average remain for at least a few days (even if the system resets often, it rarely is less than a few days except on public/shared computers), so this will do what you want. And for many, it may in fact last a year.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. The Following User Says Thank You to djr33 For This Useful Post:

    quadris (06-28-2010)

  6. #5
    Join Date
    Aug 2009
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thx :-)
    Maybe on homecomputers with static browser and IP it won't be a problem?

  7. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I'm not sure what you mean by "problem", but there are many variables and, yes, in general for the average home computer user, this will last for a while, but in fact I expect that VERY rarely it will really last for a year. Most people reset all of their cache/private data once in a while (at least once per year), and in that time they may even switch browsers or reformat the computer. Assuming that they don't do any of that, there's no reason it won't last, but you also just can't rely on it. But think about the situation: this means that once every few months they'll need to reset the system... that's not too bad.
    Basically the expiration date on a cookie should be considered as "keep until this date or until the user resets something, whichever comes first"-- so it's called an "expiration" date for a reason: it cannot be kept longer than that, but there's no reason it must be kept that long.
    If you set it for a year (or any longer time), that's basically just saying "keep until the user resets the system" and ignoring the time component.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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
  •