Showing Message before Session TimeOut

Discussions

Web tier: servlets, JSP, Web frameworks: Showing Message before Session TimeOut

  1. Showing Message before Session TimeOut (4 messages)

    We have a requirement wherein we need to display to the users a message before the session timesout, say 5 mins before the timeout, we would like to show a message like "Please save your work, else the data will be lost".

    Is something like this doable and if yes can someone pls suggest how.

    Thanks in advance

    Samir
  2. Hi,
    I guess you could use a javscript timer that pops up an alert 5 minutes before the session expires. This timer should be started whenever a page is loaded (<body onload="..." >). Googling for javascript timers I have found this time example: http://www.javascript-page.com/timer.html.
    Best regards, Mircea
  3. Hi Mircea,
    Thanks for the reply. I have thought of this option, but the problem is how can we start the counter. The counter should not start when the page is loaded but when the user stops any activity on the page/form. How do we achieve this???

    Thanks in advance

    Regards,
    Samir
  4. Hi Mircea,Thanks for the reply. I have thought of this option, but the problem is how can we start the counter. The counter should not start when the page is loaded but when the user stops any activity on the page/form. How do we achieve this???Thanks in advanceRegards,Samir
    Samir,

    You can think of it the other way. Instead of START THE COUNTER WHEN ACTIVITY STOPS, you can TOP-UP THE COUNTER WHEN ACTIVITY HAPPENS.

    -Sanjay
  5. Probably this might help you.

    Start the timer when the page is loaded. Reset the timer if the user does some action in the page.


    document.onmousedown= resetTimer
    var timerId;

    timerId = window.setTimeout("timeOut()",5000);

    function resetTimer() {
    window.clearTimeout(timerId);
    timerId = window.setTimeout("timeOut()",5000);
    }

    function timeOut(){
           // do something here
           alert("Timed out");
    }