![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||||||
| |||||||
|
|
Hey guys I have some js code as follows... ------- var SessionTimer; function StartSessionTimer() { SessionTimer = setTimeout('RedirectToSessionTimedOutPage(),60000) |
|
} function RestartSessionTimer() { clearTimeout(SessionTimer); |
|
StartSessionTimer(); } function RedirectToSessionTimedOutPage() { window.location = '/SessionTimedOut.html'; } |
|
------- When I load the page and call StartSessionTimer(), I know it works because the page redirects after ten minutes (the value of 60000). |
|
[...] To troubleshoot, if I remove the second line in the RestartSessionTimer() 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 RestartSessionTimer function; it retains its original value? |
#3
| |||
| |||
|
|
joey.pow... (AT) topscene (DOT) com wrote: Hey guys I have some js code as follows... ------- var SessionTimer; function StartSessionTimer() { SessionTimer = setTimeout('RedirectToSessionTimedOutPage(),60000) You have a syntax error in your code, the string literal is unfinished. Also, the identifier should be `sessionTimer' (as it does not designate a constructor) and the call should be `window.setTimeout(...)'. } function RestartSessionTimer() { clearTimeout(SessionTimer); window.clearTimeout(sessionTimer); StartSessionTimer(); } function RedirectToSessionTimedOutPage() { window.location = '/SessionTimedOut.html'; } This method really isn't necessary. sessionTimer = window.setTimeout( "window.location = '/SessionTimedOut.html';", 60000); ------- When I load the page and call StartSessionTimer(), I know it works because the page redirects after ten minutes (the value of 60000). 60'000 *milliseconds* are 60 seconds. That is *one* minute, _not_ ten (that would be 600'000 ms). [...] To troubleshoot, if I remove the second line in the RestartSessionTimer() 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. Quite the contrary. It is *always* being reset, in a sense. The code above looks good to me, Given your description, the code you have posted is not the code you are using, so any statement about its quality would be sheer speculation. but for some reason the SessionTimeout var does not get reset in the RestartSessionTimer function; it retains its original value? All objects cease to exist (or at least are marked for garbage collection) when the execution context they have been declared in is destroyed. That happens for the global context, and so the Global Object of which global variables are properties, whenever the document is being navigated away from, such as caused by the assignment to `window.location'. When the first `script' element in /SessionTimedOut.html is parsed, a new global execution context is created. PointedEars -- "Use any version of Microsoft Frontpage to create your site. (This won't prevent people from viewing your source, but no one will want to steal it.)" -- from <http://www.vortex-webdesign.com/help/hidesource.htm |
#4
| |||
| |||
|
|
Hey guys I have some js code as follows... ------- var SessionTimer; function StartSessionTimer() { SessionTimer = setTimeout('RedirectToSessionTimedOutPage(),60000) } function RestartSessionTimer() { clearTimeout(SessionTimer); StartSessionTimer(); } function RedirectToSessionTimedOutPage() { window.location = '/SessionTimedOut.html'; } ------- When I load the page and call StartSessionTimer(), 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 RestartSessionTimer() 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 RestartSessionTimer() 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 RestartSessionTimer function; it retains its original value? How can I fix this? Please help. JP |
#5
| |||
| |||
|
|
On Oct 26, 5:38 am, joey.pow... (AT) topscene (DOT) com wrote: Hey guys I have some js code as follows... ------- var SessionTimer; function StartSessionTimer() { SessionTimer = setTimeout('RedirectToSessionTimedOutPage(),60000) } function RestartSessionTimer() { clearTimeout(SessionTimer); StartSessionTimer(); } function RedirectToSessionTimedOutPage() { window.location = '/SessionTimedOut.html'; } ------- When I load the page and call StartSessionTimer(), 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 RestartSessionTimer() 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 RestartSessionTimer() 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 RestartSessionTimer 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? |
![]() |
| Thread Tools | |
| Display Modes | |
| |