I’ve got a Classic ASP application that relies on session; if the user leaves a screen idle and then runs a form post or other operation, I’d like to know whether the session has expired.
Currently I’m checking session in each page to see if it’s timed out, but is there a better, dynamic, JavaScripty approach that will do what banks do and time out sessions with a notification and redirect to login?
During your page’s
onloadevent, start a timer, and then redirect the page after N seconds.window.setTimeoutfunction.window.location.Reusable Example:
Quick-n-dirty Example w/ an inline function:
Note that if your page performs any AJAX calls, that keeps the session alive, so you’ll want to reset the timer using the clearTimeout method (combined w/ a new call to setTimeout). For details on clearTimeout, click here for excellent documentation from Mozilla.)