Description:

In this article, I will explain how to redirect to login page if the user is inactive or idle for long time using Jquery.

Generally, in banking websites if user stays idle for some time, automatically the page will expire and it will redirect to login page.

If there is no activity from the user for a long time, the session will time out.

In the below example program,

We are calling a function that will call for every second by using setInterval(). While calling every time, the function will increase the counter value by 1. If the counter value reaches timeout period, the page will redirect to login page.

Meantime, if the user interacts by doing any action like mousemove, key press, scroll or click event, counter value will reset and it will assign as 0.

Example Program:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript"src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
    </script>
    <script type="text/javascript">
        $(document).ready(function () {
            TimeVal = 0;
            var TimeInterval = setInterval(CallTimerInc, 1000);
            function CallTimerInc() {
                TimeVal++;
                if (TimeVal > 5) {
                    alert("Page Expired");
                    window.location.href = 'Login.aspx';
                }
            }
            $(document).bind('mousemove click mouseup mousedown keydown keypress keyup submit change mouseenter scroll resize dblclick'function (event) {
                TimeVal = 0;
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    </div>
    </form>
</body>
</html>
  

Redirect users to login page after timeout with jquery, Show alert when user is idle using Jquery, Session timeout if the user is idle using Jquery, Session expiry when the page Is idle or inactive, Detecting Idle time with jquery, Redirect users if the page is inactive or idle, Check if the user is Idle or active, Detecting user inactive using Jquery

0 comments:

Post a Comment

 
Top