473,511 Members | 15,011 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cookies shorter than a session?

I'm trying to set a cookie to expire 10 seconds after it is created.
However, it seems to last until I close all browser windows.

var objDate = new Date();
objDate.setSeconds( objDate.getSeconds() + 10 );
document.cookie = "hasSeenPopup=TRUE;";
document.cookie += "expires=" + objDate.toGMTString();

I then set the cookie to expire in 1000 seconds, to test that it could
indeed last longer than a session. However, when I close all browser
windows, the cookie is gone by the time I reopen the browser, no matter
how quickly I do this.

I am doing something incorrectly?

Aug 4 '05 #1
4 1957

I think the shortest you can get is 'session', change your approach
instead. Maybe using a server session.

Danny

Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Aug 5 '05 #2
2obvious <Ev************@gmail.com> wrote in message news:11**********************@z14g2000cwz.googlegr oups.com...
I'm trying to set a cookie to expire 10 seconds after it is created.
However, it seems to last until I close all browser windows.

var objDate = new Date();
objDate.setSeconds( objDate.getSeconds() + 10 );
document.cookie = "hasSeenPopup=TRUE;";
document.cookie += "expires=" + objDate.toGMTString();

I then set the cookie to expire in 1000 seconds, to test that it could
indeed last longer than a session. However, when I close all browser
windows, the cookie is gone by the time I reopen the browser, no matter
how quickly I do this.

I am doing something incorrectly?


It seems that a date-specified cookie can expire during a session, in as little as 10 seconds if required.

<SCRIPT type='text/javascript'>

document.write( "COOKIE DETECTED: "+ /cookieLife/.test(document.cookie) + "<BR><BR>" );

var exp=new Date(), lifeSecs=10;

document.write("System time: "+exp+"<BR><BR>");

exp.setSeconds(exp.getSeconds()+lifeSecs);

document.write("Setting expiry to system time advanced "+lifeSecs+" secs: " + exp +
"<BR><BR> Reload page to test duration.");

document.cookie="cookieLife=true;expires="+exp.toG MTString();

</SCRIPT>

--
Stephen Chalmers

547265617375726520627572696564206174204F2E532E2072 65663A205451323437393134

Aug 5 '05 #3
Stephen Chalmers wrote:
2obvious <Ev************@gmail.com> wrote in message news:11**********************@z14g2000cwz.googlegr oups.com...
I'm trying to set a cookie to expire 10 seconds after it is created.
However, it seems to last until I close all browser windows.

var objDate = new Date();
objDate.setSeconds( objDate.getSeconds() + 10 );
document.cookie = "hasSeenPopup=TRUE;";
document.cookie += "expires=" + objDate.toGMTString();

I then set the cookie to expire in 1000 seconds, to test that it could
indeed last longer than a session. However, when I close all browser
windows, the cookie is gone by the time I reopen the browser, no matter
how quickly I do this.

I am doing something incorrectly?

It seems that a date-specified cookie can expire during a session, in as little as 10 seconds if required.

<SCRIPT type='text/javascript'>

document.write( "COOKIE DETECTED: "+ /cookieLife/.test(document.cookie) + "<BR><BR>" );

var exp=new Date(), lifeSecs=10;

document.write("System time: "+exp+"<BR><BR>");

exp.setSeconds(exp.getSeconds()+lifeSecs);

document.write("Setting expiry to system time advanced "+lifeSecs+" secs: " + exp +
"<BR><BR> Reload page to test duration.");

document.cookie="cookieLife=true;expires="+exp.toG MTString();

</SCRIPT>


That seems to work pretty well in some browsers, but not in Safari.
Is there an open standard or official specification for working with
cookies? Below is a link to Netscape's 'specification' and a script
that works in Safari (as well as any other browser I tested):

<URL:http://wp.netscape.com/newsref/std/cookie_spec.html>

<URL:http://developer.apple.com/internet/safari/faq.html#anchor6>

The Netscape link is provided in the W3C's pages on cookie handling
mechanisms, so I guess it must be as good as you'll get.

<URL:http://www.w3.org/Library/src/HTCookie.html>
--
Rob
Aug 5 '05 #4
JRS: In article <42**********@mk-nntp-2.news.uk.tiscali.com>, dated
Fri, 5 Aug 2005 02:43:59, seen in news:comp.lang.javascript, Stephen
Chalmers <ig******@lycos.co.uk> posted :

exp.setSeconds(exp.getSeconds()+lifeSecs);


Using that purely as an illustration, since the time taken to do it once
is negligible :

K = 40000 ; D = new Date()
D1 = new Date()
J = K ; while (J--) D.setSeconds(D.getSeconds()+1)
D2 = new Date()
J = K ; while (J--) D.setUTCSeconds(D.getUTCSeconds()+1)
D3 = new Date()
J = K ; while (J--) D.setTime(D.getTime()+1000)
D4 = new Date()
J = K ; while (J--) {}
D5 = new Date()

x = [D2-D1, D3-D2, D4-D3, D5-D4]

gives 12140,1210,770,110

The non-UTC function (no doubt because it considers local time) is about
ten times slower than the UTC function, which is about 1.7 times slower
than directly changing the value. In my system.

Javascript will look a bit odd if the M.....s manage to abolish UTC; JS
should have used GMT instead.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Aug 5 '05 #5

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

Similar topics

1
2796
by: windandwaves | last post by:
Hi Gurus I am basically sorry that I have to bother you about this. I am a PHP beginner and I have been studying sessions and cookies over the last few weeks. I have learned lots, but I am...
2
3323
by: Amit D.Shinde | last post by:
Hello Experts.. I need some help regarding cookies and session objects and also global.asa file I am creating one cookie when a user logs in on my website. The cookie stores the login name of...
3
2080
by: Marcin Gorzynski | last post by:
Hi Our partner is using our page in a frame. That couses a problem because our domain is unable to issue the cookie also session does not work. each time you click in the frame new session is...
7
1987
by: Marcus | last post by:
I know that when you start a session in PHP, the "cookie" it creates is not the same as those that are stored in your browser's temp folder, and instead is kept in RAM. I am confused because in...
6
6430
by: Paul | last post by:
Here is a question that should get everyone going. I have an ecommerce site where I need to pass the order_id to every page. So which method is the best practice to pass this variable between...
3
1594
by: Mark | last post by:
I'm told that ram based cookies refer to session cookies (which the browser may still store on disk if it likes). These cookies that are destroyed when the bowser exits. If they are "session...
24
2394
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How can I see in javascript if a web browser accepts cookies?...
5
5548
by: jheines | last post by:
I am trying to explain how cookies and sessions work in a class I teach, but I have hit a wall when it comes to the interaction between cookies and the state of the privacy settings in Internet...
2
4994
by: StanB | last post by:
I came across this weird problem: 1. Session state stops working after the app is deployed to another server because IE does not accept cookies. 2. It works if cookieless="true" in the...
0
7245
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7085
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7512
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5671
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3214
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1577
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.