Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cookie expire 1

Status
Not open for further replies.

mike314

Programmer
Jun 24, 2003
143
US
I'm trying to expire this cookie but its not expiring
basically I want it to expire x minutes in milliseconds after the time its created, x being the parameter you set
is there anything obvious??


var cookiePath = ";Path=/";
function setCookie(cookieName, cookieValue, expirenumber)
{
if (cookieValue != null && cookieValue != "")
var dy = new Date()
cookieValue = escape(cookieValue);
document.cookie=cookieName + "=" + cookieValue + ((expirenumber) ? ";expires="+dy.getTime()+ expirenumber : ";expires=" + cookieExpires.toGMTString()) + cookiePath;
cookieString = document.cookie;
}
 
In both cases in your terniary operator, you need to make sure the date is in .toGMTString() format.
Code:
 document.cookie=cookieName + "=" + cookieValue + ((expirenumber) ? ";expires="+[!]([/!]dy.getTime()+ expirenumber[!]).toGMTString()[/!] : ";expires=" + cookieExpires.toGMTString()) + cookiePath;
**My code might break, you would maybe need to parse as date


<.

 
thanks got it

i used:
dy.setTime(Date.parse(dy.toGMTString()) + expirenumber)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top