PDA

View Full Version : Ajax Tabs Content Script (v 2.2) WITH COOKIES?



quadris
06-24-2010, 02:32 PM
1) Script Title: Ajax Tabs Content Script (v 2.2)

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/ajaxtabscontent/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 ! :-)

ddadmin
06-25-2010, 08:43 AM
Try changing the line:


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

to:


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.

quadris
06-28-2010, 07:40 AM
Try changing the line:


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

to:


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.

djr33
06-28-2010, 08:03 AM
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.

quadris
06-28-2010, 08:33 AM
Thx :-)
Maybe on homecomputers with static browser and IP it won't be a problem?

djr33
06-28-2010, 08:49 PM
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.