473,770 Members | 4,029 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

setTimeout - clearTimeout - Why Doesn't This Work?

Hey guys I have some js code as follows...

-------

var SessionTimer;

function StartSessionTim er()
{
SessionTimer = setTimeout('Red irectToSessionT imedOutPage(),6 0000)
}

function RestartSessionT imer()
{
clearTimeout(Se ssionTimer);
StartSessionTim er();
}

function RedirectToSessi onTimedOutPage( )
{
window.location = '/SessionTimedOut .html';
}

-------

When I load the page and call StartSessionTim er(), I know it works
because the page redirects after ten minutes (the value of 60000).
However, in certain situations I need to be able to call back to the
server with AJAX and then have the timer reset - that's when I call
the RestartSessionT imer() function. When I do this, for some reason
the ten minute window does not get reset.

To troubleshoot, if I remove the second line in the
RestartSessionT imer() function the redirect is getting blocked (as
planned). However, when I put the second line back in, the page just
redirects as originally called - the SessionTimeout value is never
reset properly.

The code above looks good to me, but for some reason the
SessionTimeout var does not get reset in the RestartSessionT imer
function; it retains its original value?

How can I fix this?

Please help.

JP

Oct 25 '07 #1
2 6718
On Oct 26, 5:38 am, joey.pow...@top scene.com wrote:
Hey guys I have some js code as follows...

-------

var SessionTimer;

function StartSessionTim er()
{
SessionTimer = setTimeout('Red irectToSessionT imedOutPage(),6 0000)

}

function RestartSessionT imer()
{
clearTimeout(Se ssionTimer);
StartSessionTim er();

}

function RedirectToSessi onTimedOutPage( )
{
window.location = '/SessionTimedOut .html';

}

-------

When I load the page and call StartSessionTim er(), I know it works
because the page redirects after ten minutes (the value of 60000).
However, in certain situations I need to be able to call back to the
server with AJAX and then have the timer reset - that's when I call
the RestartSessionT imer() function. When I do this, for some reason
the ten minute window does not get reset.

To troubleshoot, if I remove the second line in the
RestartSessionT imer() function the redirect is getting blocked (as
planned). However, when I put the second line back in, the page just
redirects as originally called - the SessionTimeout value is never
reset properly.

The code above looks good to me, but for some reason the
SessionTimeout var does not get reset in the RestartSessionT imer
function; it retains its original value?

How can I fix this?

Please help.

JP
hi joey,

I had the same problem too. I understand your problem. Have you found
any solutions yet?
Dec 6 '07 #2
I've had the same problem too! Using AJAX and clearTimer doesn't seem
to be working for me either.

-Danny
On Dec 5, 10:25 pm, "stv_...@yahoo. com" <stv_...@yahoo. comwrote:
On Oct 26, 5:38 am, joey.pow...@top scene.com wrote:
Hey guys I have some js code as follows...
-------
var SessionTimer;
function StartSessionTim er()
{
SessionTimer = setTimeout('Red irectToSessionT imedOutPage(),6 0000)
}
function RestartSessionT imer()
{
clearTimeout(Se ssionTimer);
StartSessionTim er();
}
function RedirectToSessi onTimedOutPage( )
{
window.location = '/SessionTimedOut .html';
}
-------
When I load the page and call StartSessionTim er(), I know it works
because the page redirects after ten minutes (the value of 60000).
However, in certain situations I need to be able to call back to the
server with AJAX and then have the timer reset - that's when I call
the RestartSessionT imer() function. When I do this, for some reason
the ten minute window does not get reset.
To troubleshoot, if I remove the second line in the
RestartSessionT imer() function the redirect is getting blocked (as
planned). However, when I put the second line back in, the page just
redirects as originally called - the SessionTimeout value is never
reset properly.
The code above looks good to me, but for some reason the
SessionTimeout var does not get reset in the RestartSessionT imer
function; it retains its original value?
How can I fix this?
Please help.
JP

hi joey,

I had the same problem too. I understand your problem. Have you found
any solutions yet?
Dec 14 '07 #3

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

Similar topics

1
11954
by: Mike | last post by:
Hey, I posted a question yesterday that was pretty confusing. I've figured out some of it for myself, but there's still one issue that I can't figure out, and I've been trying for months now! I have a pop-up menu; one of those where you scroll over the menu, and a submenu pops up beneath it. Everything's running smoothly on every browser I've tested with, except for one problem on every browser: the "clearing" of the menu.
1
1628
by: Better but still clumpsy | last post by:
Hi, I have a script that is looping like this : for (i=0;i<100;i++) { do 1 do 2 display setTimeout("timer",1000);
2
4672
by: Athanasius | last post by:
Could someone shed some light as to why the following setTimeout function will not work on the Mac IE5.2? It does however work on PC(Forefox,Netscape,IE) & Mac(Safari,Firefox). Here is the script, it should simply present an alert message after 5 seconds. Thanks. <html> <head> <script language="javascript"> function MsgTimer() { var self = this;
2
7692
by: JellyON | last post by:
Hi. I'm a little bit lost trying to insert a setTimeout() for recursive call containing string and numeric parameters. Here is a generic example of what I would like to succeed to do : function Stuff(a_str, an_int, delay) { // Three useful vars for managing the recursivity var stop = false; // will be true when no more recurse needed var command; // just to concatenate the recurse expression
6
2253
by: Brent | last post by:
Is there any obvious reason why there's no delay in the execution of setting the id.style.display when this function gets called? function Hide(divId,timeout) { var id = document.getElementById(divId); setTimeout(id.style.display = 'none',timeout); } Thanks for any help.
12
5556
by: Andrew Poulos | last post by:
With the following code I can't understand why this.num keeps incrementing each time I create a new instance of Foo. For each instance I'm expecting this.num to alert as 1 but keeps incrementing. Foo = function(type) { this.num = 0; this.type = type this.trigger(); } Foo.prototype.trigger = function() {
4
2125
by: Rene | last post by:
Hi, first things first, please take a second to check out the page on the link below. http://bookofjavascript.com/Chapter13/Assignment.html In this page, you are supposed to click on the "Make Happiness Bounce" button to make the smiley face start bouncing and then you can click the "Stop that Smiley!" button to stop it. What I find odd about this example is that if I click the "Make Happiness
3
5779
by: naurus | last post by:
i'd like to know what set timeout does after its finished. I have a script that starts a timeout right before sending an SJaX request that timesout after 1000 milliseconds and abort()s the SJaX request and sets some things then alerts me that it timed out. After i click ok on the alert, my browser (FF) crashes every time. I'd just like to know what happens after the timeout is finished. Here is my code: var changeBG; function...
1
9537
by: bizt | last post by:
Hi, I have a process where every so often I refresh a table's data using a setTimeout() .. and when its no longer needed, a clearTimeout(). The following is a simple example of how this is done: var goMenuTimeout = null; function LoadMenu() { // cancel any repeat actions
0
9602
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9439
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10071
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10017
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8905
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7431
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2832
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.