Page 1 of 1
On lost focus
Posted: Sat Jan 03, 2004 9:54 am
by fastfingertips
I have a countdown running on a page, and I want if the page is losing the focus to stop this countdown and when the focus is received again to start again but not from initial moment. Can you give me please a suggestion?
Posted: Sat Jan 03, 2004 2:04 pm
by Gen-ik
Something like this might work...
Code: Select all
<html>
<head>
<script type="text/javascript">
timeToWait = 10; // Seconds
timePassed = 0;
function StartTimer() { timerINT = setInterval("RunTimer()", 1000); }
function StopTimer() { clearInterval(timerINT); }
function RunTimer()
{
timePassed ++
if(timePassed == timeToWait)
{
StopTimer();
alert("GAME OVER");
}
}
</script>
</head>
<body onload="StartTimer()" onblur="StopTimer()">
Some text
</body>
</html>