javascript計算用戶打開網(wǎng)頁的停留時間
更新時間:2014年01月09日 16:25:03 作者:
本文介紹了javascript計算用戶打開網(wǎng)頁的停留時間,大家參考使用吧
復(fù)制代碼 代碼如下:
<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>
相關(guān)文章
JavaScript中click和onclick本質(zhì)區(qū)別與用法分析
這篇文章主要介紹了JavaScript中click和onclick本質(zhì)區(qū)別與用法,結(jié)合實例形式分析了JavaScript中click和onclick的具體概念、功能、使用場景及相關(guān)操作技巧,需要的朋友可以參考下2018-06-06JS小功能(setInterval實現(xiàn)圖片效果顯示時間)實例代碼
這篇文章主要介紹了setInterval實現(xiàn)圖片效果顯示時間實例代碼,有需要的朋友可以參考一下2013-11-11