| 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] |