1

I have implemented a session timeout using JQuery plugin and its been implemented like, from page loads, it starts the timer and after 10 seconds, a popo-up will be shown. something like this http://rigoneri.github.com/timeout-dialog.js/

function ShowTimeoutWarning(){
$.timeoutDialog({timeout: 1, countdown: 60, restart_on_yes: false});

}

setTimeout( 'ShowTimeoutWarning();', 100000 ); 

This code works fine when the user is idle for 10 seconds. But even though the user is doing some operation on the page, the popup is displayed, no matter the user is idle or not. I want this code to be run only when the user is idle. Please help me on this regard.

Thanks!!!

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
madhu
  • 1,010
  • 5
  • 20
  • 38

3 Answers3

1

Have a common javascript function that starts a setTimeout(). Note that this should be a time less than the session timeout defined in the web.xml. So when that timeout expires you give a warning to the user asking whether to invalidate the session or not. On every server call and every page reload you reset this setTimeout().

Hope this helps.

dinukadev
  • 2,279
  • 17
  • 22
  • A small clarification,.. I have 4 pages excluding the login page. Do i need to write this script setTimeout() in all the 4 pages? And how do I call this function when session-timeout expires?? Is it in the controller??? – madhu Nov 30 '12 at 05:41
  • normally what we would do is use the include jsp tag in order to import common java script files required for all pages so that all future pages will also inherit from the same included jsp which imports the required common javascript files. On page load you execute the setTimeout() after the DOM is ready. – dinukadev Nov 30 '12 at 05:44
0

This is done with a timer and some JavaScript. When the timer expires on the page, the browser requests a URL that calls session.invalidate() on the server.

jonathan.cone
  • 6,592
  • 2
  • 30
  • 30
0

You should try the jQuery idleTimer plugin http://www.paulirish.com/2009/jquery-idletimer-plugin/

<script type="text/javascript">

    $(function () {
        var timeout = 10000;
        $(document).bind("idle.idleTimer", function () {
            // function you want to fire when the user goes idle
            $.timeoutDialog({ timeout: 0.25, countdown: 30, keep_alive_url: '/KeepAlive.aspx', logout_redirect_url: '/Signin.aspx', restart_on_yes: true });
        });
        $(document).bind("active.idleTimer", function () {
            // function you want to fire when the user becomes active again                
            $.get('KeepAlive.aspx?date=' + escape(new Date()));
        });
        $.idleTimer(timeout);
    });

</script>
Mike Eber
  • 184
  • 7