473,320 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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.
Jul 19 '05 #1
2 19825
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.)

Jul 19 '05 #2
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." <no**@hotmail.com> wrote in message
news:ux**************@TK2MSFTNGP10.phx.gbl...
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.

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: chrism | last post by:
Hello, I have a pop-up window that I would like to appear in front of the browser home page when a user opens IE. Problem is, I'd like it to never appear again if the user navigates back to the...
1
by: Hardeep Rakhra | last post by:
Hi i have a snippet of JS that i want to change so that the cookie it creates lasts only 48 hours. (or any other length of time i decide, but 48hours seems right for now) Only thing i can't...
7
by: What-a-Tool | last post by:
How does the expire date work setting it server side with asp. I know with javascript setting it client side it will be set to the clients local time, and therefore expire when the clients local...
3
by: HorseGeek | last post by:
I can't find a cookie that my code is writing. The behavior of my webpages indicates that the cookie IS being written SOMEPLACE. However, I can't find it. My client does not want the code going...
4
by: Aki | last post by:
Hi, I have a problem with writing cookies in IE. The code works fine in Netscape 7.2, Opera 8 and Firefox 1.04. In IE 6 the cookie isn't written. I run WinXP SP2. I'm trying to show a...
9
by: Marco Krechting | last post by:
Hi All, I have a page with a list of hyperlinks. I want to save information in a cookie about the fact that I entered an hyperlink or not. When I click one of the hyperlinks I want this stored...
1
by: Joe | last post by:
Hi folks, Been looking at this for the day so any ideas would be appreciated. Here's the scenario, bear with me - it looks more complicated than it is :) I have a page templating system that...
23
by: Phil Powell | last post by:
// OBTAINED FROM http://www.javascripter.net/faq/settinga.htm // NOTE THAT IF YOU SET days TO -1 THE COOKIE WILL BE SET TO YESTERDAY AND THUS EXPIRE function setCookie(name, value, days, docObj)...
6
by: mymatebob | last post by:
Hi, I am using cookies to keep track if a user is logged into my system, and would like to display the time that the user has left logged in. One solution is to display the time left until the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.