Wednesday, 16 March 2016

Session out From login page to Logout page using JavaScript

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
//<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js" 
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        var idleTime = 0;
        $(document).ready(function () {
            //Increment the idle time counter every minute.
            var idleInterval = setInterval(timerIncrement, 60000); // 1 minute

            //Zero the idle timer on mouse movement.
            $(this).mousemove(function (e) {
                idleTime = 0;
            });
            $(this).keypress(function (e) {
                idleTime = 0;
            });
        });

        function timerIncrement() {
            //alert('Alert');
            idleTime = idleTime + 1;
            if (idleTime > 15) { // 16 minutes
                window.location.href = "http://local/Logout.aspx"
            }
        }

    </script>
</head>
<body>
    <form id="form1" runat="server" >
    <div >
        <h1>
            WebForm</h1>
    </div>
    </form>
</body>
</html>