JavaScript - how to logout with confirm button when page opens idle for 2 mins ?

Asked By Aravind Aravind on 03-Jun-13 01:40 AM
Hai Everyone
I am decide to redirect to login page when website is open and idle for 2 mins,i have 5 to 6 web pages,after login to website it goes to main page,if user not work or it doesn't use for 2 mins when again user click any link or menus one confirm message is appear and redirect to login page and clear all sessions.
Note: May be use time limit in web.config file
 

Below code is work when i click page,i want without click it automatically pop up the alert message.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
 
 <script>
var logoutUser = false;
var timeoutHnd = null;
var logouTimeInterval = 3000;// Three Second
function onuser_activite(){
    if(logoutUser){
    alert("You Session Expired");
    window.location.href = "Logout.aspx";
    }
    else{
        ResetLogOutTimer();
    }
}
function OnTimeoutReached(){
logoutUser = true;
}
function ResetLogOutTimer(){
clearTimeout(timeoutHnd);
// set new timer
timeoutHnd = setTimeout('OnTimeoutReached();',logouTimeInterval);
}
 

</script>
 
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="tbxarea" runat="server" title="Write your name here"></asp:TextBox>
    </div>
    </form>
 
    <script>document.body.onclick = onuser_activite;
    timeoutHnd = setTimeout('OnTimeoutReached();',logouTimeInterval);
    </script>
</body>
</html>



Pls reply me asap...
 
Thans
Aravind
Reena Jain replied to Aravind Aravind on 03-Jun-13 02:34 AM
Hi,

Just use cache concept for this.

Hope this will help you
Robbe Morris replied to Aravind Aravind on 03-Jun-13 09:35 AM
This would be easier to manage with setInterval instead of setTimeout.  You wouldn't have to keep clearing and resetting stuff.  It just keeps checking every x milliseconds. if logoutUser == true, then perform the action in OnTimeoutReached.  All you are currently doing their is setting a flag.  You'd want to just set the window.location.href = 'logout.aspx' as well.