Connecting Tech Pros Worldwide Help | Site Map

Ever tried to set cookie expiry date using JavaScript?

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 19th, 2005, 07:46 AM
Vince C.
Guest
 
Posts: n/a
Default Ever tried to set cookie expiry date using JavaScript?

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.



  #2  
Old July 19th, 2005, 07:46 AM
MSFT
Guest
 
Posts: n/a
Default 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/javascri...25/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.)

  #3  
Old July 19th, 2005, 07:46 AM
Steve Lutz
Guest
 
Posts: n/a
Default 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]


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.