М.б. как-то так?
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8"
</head>
<body>
<form name="frm" action="http://">
<input name="clock">
</form>
<script>
var mya = true, tm, vtime = 0;
function startClock(parm) {
if (parm == "stop") {
clearTimeout(tm);
}
else {
document.forms['frm'].clock.value = vtime;
vtime++;
tm = setTimeout(startClock, 1000);
}
}
startClock("start");
var handleChange = function () {
if (!document.hidden) {
startClock("start");
} else {
startClock("stop");
}
};
window.addEventListener('visibilitychange', handleChange);
</script>
</body>
</html>