• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 580
  • Last Modified:

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.setDate(new Date().getDate()+days).toGMTString()
        document.cookie = name+"="+value+"; path=/"+expirestr
      }
0
TCCIRM
Asked:
TCCIRM
  • 7
  • 4
2 Solutions
 
leakim971PluritechnicianCommented:
get the old value first (getCookie(c_name)) and recreate (setCookie:function(name, value, days)) it with the new expiration date :)
0
 
imaki06Commented:
You should find the call to that setCookie-function.

There is three parameters name, value and amount of days. Change the last parameter to 360, and thats it..

Like this:
setCookie("name","cookie value", 360);
0
 
TCCIRMAuthor Commented:
So modification to this string will not do the trick?

expirestr="; expires="+expireDate.setDate(new Date().getDate()+days).toGMTString()

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
leakim971PluritechnicianCommented:
setCookie(myCookieName, getCookie(myCookieName), 360);

Open in new window

0
 
TCCIRMAuthor Commented:
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.setDate(new Date().getDate()+days).toGMTString()  
      document.cookie = name+"="+value+"; path=/"+expirestr
      }
}
0
 
leakim971PluritechnicianCommented:
>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
0
 
TCCIRMAuthor Commented:
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...
0
 
TCCIRMAuthor Commented:
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
0
 
TCCIRMAuthor Commented:
Still plugging away...  still not able to make the leap...  
0
 
leakim971PluritechnicianCommented:
If you place alert/console.log as first command of setCookie and getCookie do you get/see them ?
0
 
TCCIRMAuthor Commented:
As you tell by now, I'm not real adept with JavaScript...  I tried the following but it throws and error:

alert( document.cookie("fluidtextresizer") );

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....
0
 
TCCIRMAuthor Commented:
Answers were not specfic to my problem.  Moving on...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now