js记录用户停留的时间,代码:
<script language="javascript"> var second = 0; var minute = 0; var hour = 0; var time; window.setTimeout("staytime();", 1000); function staytime() { second++; if (second == 60) { second = 0; minute += 1; } if (minute == 60) { minute = 0; hour += 1; } window.onbeforeunload = function () { alert(time); } time = hour + "小时" + minute + "分" + second + "秒"; window.setTimeout("staytime();", 1000); } </script>