码迷,mamicode.com
首页 > Web开发 > 详细

JS实现显示来访者的停留时间

时间:2016-12-28 07:37:54      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:nav   get   ide   false   value   clock   doc   ring   class   

显示来访者的停留时间

<script language="javascript">
var ap_name = navigator.appName;
var ap_vinfo = navigator.appVersion;
var ap_ver = parseFloat(ap_vinfo.substring(0,ap_vinfo.indexOf(‘(‘)));
var time_start = new Date();
var clock_start = time_start.getTime();
var dl_ok=false;
function init ()
{
if(ap_name=="Netscape" && ap_ver>=3.0)
dl_ok=true;
return true;
}
function get_time_spent ()
{
var time_now = new Date();
return((time_now.getTime() - clock_start)/1000);
}
function show_secs () // show the time user spent on the side
{
var i_total_secs = Math.round(get_time_spent());
var i_secs_spent = i_total_secs % 60;
var i_mins_spent = Math.round((i_total_secs-30)/60);
var s_secs_spent = "" + ((i_secs_spent>9) ? i_secs_spent : "0" + i_secs_spent);
var s_mins_spent = "" + ((i_mins_spent>9) ? i_mins_spent : "0" + i_mins_spent);
document.fm0.time_spent.value = s_mins_spent + ":" + s_secs_spent;
window.setTimeout(‘show_secs()‘,1000);
}
// -->
</script>
<FORM name="fm0" onSubmit="0"><FONT COLOR="#6060FF">停留时间:
</FONT><INPUT type="text" name="time_spent" size=7 onFocus="this.blur()"></FORM>

然后在主页源文件<body>标签内加入

<BODY onLoad="init(); window.setTimeout(‘show_secs()‘,1);">

 

JS实现显示来访者的停留时间

标签:nav   get   ide   false   value   clock   doc   ring   class   

原文地址:http://www.cnblogs.com/puamap/p/6228069.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!