views:

98

answers:

2
<script type="text/javascript">
var t;
function startTimer(){
t=setTimeout("document.location='../login/logout.php'", 50000);
}

function  stopTimer(){
clearTimeout(t);
}
</script>

This is my script for auto logout,

i want to show the countdown timer, How to create and show the timer,

Also i want to make alive when the user hit the body of the page,

Also timer should reset and then restart again when system is idle,

How to make it,

(Timer should show , that is , timer should run when people not touching the system ,

if user touch the system then counter should restart )

A: 

Hiya,

my example:

Updated to check if the user is Idle (is set to 2 seconds, this makes testing easier, i'd recommend at least 5 or 10 minutes).

<body onload="setTimeout('startCountDown()',2000);" onmousemove="resetTimer();">

<form name="counter"><input type="text" size="5" name="timer" disabled="disabled" /></form> 


<script type="text/javascript"> 
<!--   
 // edit startSeconds as you see fit 
 // simple timer example provided by Thomas

 var startSeconds = 10;
 var milisec = 0;
 var seconds=startSeconds;
 var countdownrunning = false
 var idle = false;
 document.counter.timer.value=startSeconds;

function CountDown()
{ 
    if(idle == true)
    {

        if (milisec<=0)
        { 
            milisec=9 
            seconds-=1 
        } 
        if (seconds<=-1)
        { 
            document.location='../login/logout.php';
            milisec=0 
            seconds+=1 
            return;
        } 
        else 
        milisec-=1; 
        document.counter.timer.value=seconds+"."+milisec;
        setTimeout("CountDown()",100);
    }
    else
    {
        return;
    } 
}
function startCountDown()
{
   document.counter.timer.value=startSeconds;
   seconds = startSeconds;
   milisec = 0

   document.counter.timer.style.display = 'block';
   idle = true;
   CountDown();
   document.getElementById("alert").innerHTML = 'You are idle. you will be logged out after ' + startSeconds + ' seconds.';
   countdownrunning = false;   
}

function resetTimer()
{ 
    document.counter.timer.style.display = 'none';
    idle = false;    
    document.getElementById("alert").innerHTML = '';


    if(!countdownrunning)
        setTimeout('startCountDown()',2000);

    countdownrunning = true;

}

--> 
</script>
Stephen
i just commented millisec , i just ran the script with second. but its not working for me,
Bharanikumar
Doesn't work without milisec... however you can display it without msec...Edit this line:document.counter.timer.value=seconds+"."+milisec;to:document.counter.timer.value=seconds;in function CountDown() ;) good luck
Stephen
A: 

i hope you can make use of this

http://webpages.cs.luc.edu/~laufer/424/StopwatchJQuery/

zod