Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Ever tried to set cookie expiry date using JavaScript?

Question posted by: Vince C. (Guest) on July 19th, 2005 07:46 AM
Hi all.

I'm trying to set a cookie expiry date but my script is JS (JavaScript). I've
tried

Response.Cookies("Test").Expires = Date();
Response.Cookies("Test").Expires = Date().toLocaleString();
Response.Cookies("Test").Expires = Date().toString();
Response.Cookies("Test").Expires = Date().toUTCString();

none works. I've seen what bothers IIS is the day name when assigning the expiry
date: "7 février 2004 11:57:57" is ok while "samedi 7 février 2004 11:57:57"
produces an error "Invalid type".

Ok, I could switch to VB Script (which I think I'll do because of the ease of
doing it in that language). But I'd like to know if there are well-known tricks
on using IIS/ASP and cookies expiry date in JavaScript. It seems IIS object
model is unable to recognize (or handle) JavaScript dates...

Might sound a stupid question but I'd like my script to be as platform
independent as possible. Why? I'm running a French version of Windows 2000/IIS5.
I might have to host my web on an English version. Or whatsoever. I wouldn't
like to triturate the date string for it depends on the current locale. If
JavaScript cannot be used without modifying the string I'll switch to VB script.

Thanks for any hint or suggestion.

Vince C.


Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
MSFT's Avatar
MSFT
Guest
n/a Posts
July 19th, 2005
07:46 AM
#2

Re: Ever tried to set cookie expiry date using JavaScript?
Hi Vince,

Based on my experience, we may use JavaScript and Date function to set
cookies on client side, for example:

http://www.webreference.com/javascr...125/source.html

On server side, we can convert the date to a string like "mm/dd/yyyy" or
use VB script instead.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Steve Lutz's Avatar
Steve Lutz
Guest
n/a Posts
July 19th, 2005
07:46 AM
#3

Re: Ever tried to set cookie expiry date using JavaScript?
I use this little function when making a cookie in javascript. It seems to
work all the time.

function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}


"Vince C." <none@hotmail.com> wrote in message
news:uxaRBA3iDHA.2416@TK2MSFTNGP10.phx.gbl...[color=blue]
> Hi all.
>
> I'm trying to set a cookie expiry date but my script is JS (JavaScript).[/color]
I've[color=blue]
> tried
>
> Response.Cookies("Test").Expires = Date();
> Response.Cookies("Test").Expires = Date().toLocaleString();
> Response.Cookies("Test").Expires = Date().toString();
> Response.Cookies("Test").Expires = Date().toUTCString();
>
> none works. I've seen what bothers IIS is the day name when assigning the[/color]
expiry[color=blue]
> date: "7 février 2004 11:57:57" is ok while "samedi 7 février 2004[/color]
11:57:57"[color=blue]
> produces an error "Invalid type".
>
> Ok, I could switch to VB Script (which I think I'll do because of the ease[/color]
of[color=blue]
> doing it in that language). But I'd like to know if there are well-known[/color]
tricks[color=blue]
> on using IIS/ASP and cookies expiry date in JavaScript. It seems IIS[/color]
object[color=blue]
> model is unable to recognize (or handle) JavaScript dates...
>
> Might sound a stupid question but I'd like my script to be as platform
> independent as possible. Why? I'm running a French version of Windows[/color]
2000/IIS5.[color=blue]
> I might have to host my web on an English version. Or whatsoever. I[/color]
wouldn't[color=blue]
> like to triturate the date string for it depends on the current locale. If
> JavaScript cannot be used without modifying the string I'll switch to VB[/color]
script.[color=blue]
>
> Thanks for any hint or suggestion.
>
> Vince C.
>
>[/color]



 
Not the answer you were looking for? Post your question . . .
184,040 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors