我想測量用戶使網站保持關注的時間,但它不起作用。一個簡單的JavaScript不起作用
<!doctype html>
<head>
<script>
var timeActive;
function timeActiveFuncStart(){
timeActive = 0;
function timeActiveFunc(){
timeActive++;
setTimeout("timeActiveFunc()", 1000)}}
var timeActiveTotal;
function timeActiveTotalFunc(){
timeActiveTotal = timeActiveTotal + timeActive}
document.getElementById("timeActiveP").innerHTML = timeActive;
document.getElementById("timeActiveTotalP").innerHTML = timeActiveTotal;
</script>
</head>
<body onfocus="timeActiveFuncStart()" onblur="timeActiveTotalFunc()">
<p id="timeActiveP"></p>
<p id="timeActiveTotalP"></p>
</body>
</html>
檢查了這一點http://stackoverflow.com/questions/6939047/does-html-body- tag-have-an-onblur-event – JJF
保持瀏覽器的[JavaScript控制檯](http://webmasters.stackexchange.com/questions/8525/how-to-open-the-javascript-console-in-different-browsers)打開。您可以在那裏看到錯誤消息。 – JJJ