例子,js统计与显示网页停留时间的代码。
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>显示网页停留时间_www.jb200.com</title>
</head>
<body bgcolor="#336699" onunload="bye()">
<script language="javascript">
<!-- begin
pageopen = new date();
function bye() {
pageclose = new date();
minutes = (pageclose.getminutes() - pageopen.getminutes());
seconds = (pageclose.getseconds() - pageopen.getseconds());
time = (seconds + (minutes * 60));
if (time == 1) {
time = (time + " 秒钟");
}
else {
time = (time + " 秒钟");
}
alert('您在这儿呆了' + time + '.欢迎再来!');
}
// end -->
</script>
</body>
</html>