I need to make it so if the user is watching the timer and view the site related to the timer and he should open a new tab to browse a different site the timer stops until they go back to the correct tab.
Here is the code I have
Code: Select all
<script type="text/javascript">
var isActive;
window.onfocus = function () {
isActive = true;
document.getElementById("clock").style.display="display";
document.getElementById("alert").innerHTML="";
};
window.onblur = function () {
isActive = true;
//document.getElementById("alert").innerHTML="Timer Paused ! Click here to Activate it Again.";
};
function startClock() {
if(isActive == true)
{
var the_timer = window.document.the_form.clock.value;
the_timer = parseInt(the_timer) - 1;
window.document.the_form.clock.value = the_timer;
}
the_timeout = setTimeout("startClock();",1000);
if (the_timer == 0) {
document.getElementById("clock").style.display="none";
window.onblur = function () {
document.getElementById("alert").innerHTML="";
};
var answer = "";
x = answer;
document.the_form.clock.value = x;
clearTimeout(the_timeout);
var code = "<?php
if($loggedin==1)
{
$site_code = md5(time().sha1(microtime()));
} else {
$site_code = "undefined";
}
$_SESSION["adcode"] = $site_code;
echo $_SESSION['adcode'];
?>";
var ad= "<?php echo $_GET['ad']; ?>";
success.location.href="success.php?ad="+ad+"&code="+code+"&verify=1";
}
}
</script>