TCCIRM
asked on
Changing cookie expiration
I am running a script that currently sets a cookie that expires at the end of the session when the browser close's. I would like to set the expiration date for 360 days. Not sure how to make this change in the following code:
setCookie:function(name, value, days){
var expirestr=''
if (typeof days!="undefined") //if set persistent cookie
expirestr="; expires="+expireDate.setDa te(new Date().getDate()+days).toG MTString()
document.cookie = name+"="+value+"; path=/"+expirestr
}
setCookie:function(name, value, days){
var expirestr=''
if (typeof days!="undefined") //if set persistent cookie
expirestr="; expires="+expireDate.setDa
document.cookie = name+"="+value+"; path=/"+expirestr
}
get the old value first (getCookie(c_name)) and recreate (setCookie:function(name, value, days)) it with the new expiration date :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
So modification to this string will not do the trick?
expirestr="; expires="+expireDate.setDa te(new Date().getDate()+days).toG MTString()
expirestr="; expires="+expireDate.setDa
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Okay I'm following you somewhat... I'm deconstucting this to learn. I think I should have included the entire routine: This is not as clear cut as I thought it was. The cookies name is fluidtextresizer. So by calling the old value (if it is available) first... then set the expiration date?
fluidtextresizer.routines= {
getCookie:function(Name){
var re=new RegExp(Name+"=[^;]*", "i"); //construct RE to search for target name/value pair
return (document.cookie.match(re) )? document.cookie.match(re)[ 0].split(" =")[1] : null //return cookie value if found or null
},
setCookie:function(name, value, days){
var expirestr=''
if (typeof days!="undefined") //if set persistent cookie
expirestr="; expires="+expireDate.setDa te(new Date().getDate()+days).toG MTString()
document.cookie = name+"="+value+"; path=/"+expirestr
}
}
fluidtextresizer.routines=
getCookie:function(Name){
var re=new RegExp(Name+"=[^;]*", "i"); //construct RE to search for target name/value pair
return (document.cookie.match(re)
},
setCookie:function(name, value, days){
var expirestr=''
if (typeof days!="undefined") //if set persistent cookie
expirestr="; expires="+expireDate.setDa
document.cookie = name+"="+value+"; path=/"+expirestr
}
}
>The cookies name is fluidtextresizer. So by calling the old value (if it is available) first... then set the expiration date?
yes, if it not exist you're just creating a cookie with a null value
yes, if it not exist you're just creating a cookie with a null value
ASKER
Yeah I'm not getting it... Can't seem to adapt your recommendations into the code I have and get it to work.... The principle makes sense, application does not...
ASKER
I guess the crazy part is I can get the simple application to work but this script is a little more complicated. Complete script attached... fluidtextresizer.js
ASKER
Still plugging away... still not able to make the leap...
If you place alert/console.log as first command of setCookie and getCookie do you get/see them ?
ASKER
As you tell by now, I'm not real adept with JavaScript... I tried the following but it throws and error:
alert( document.cookie("fluidtext resizer") );
Using FF cookie viewer I am able to view the values and can see whether my modifications are working. I've been able to create a simple cookie separate from the script I attached. I am forced to use this script but have not been able to make the leap....
alert( document.cookie("fluidtext
Using FF cookie viewer I am able to view the values and can see whether my modifications are working. I've been able to create a simple cookie separate from the script I attached. I am forced to use this script but have not been able to make the leap....
ASKER
Answers were not specfic to my problem. Moving on...