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="">
<head runat="server">
    <title>Untitled Page</title>
var logoutUser = false;
var timeoutHnd = null;
var logouTimeInterval = 3000;// Three Second
function onuser_activite(){
    alert("You Session Expired");
    window.location.href = "Logout.aspx";
function OnTimeoutReached(){
logoutUser = true;
function ResetLogOutTimer(){
// set new timer
timeoutHnd = setTimeout('OnTimeoutReached();',logouTimeInterval);

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

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

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.