On lost focus
Moderator: General Moderators
-
fastfingertips
- Forum Contributor
- Posts: 242
- Joined: Sun Dec 28, 2003 1:40 am
- Contact:
On lost focus
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?
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>