网站地图    收藏   

主页 > 前端 > javascript >

javascript显示页面停留时间几个实例总结

来源:自学PHP网    时间:2014-09-19 14:47 作者: 阅读:

[导读] 有时我们会看到有些网站可以记录你进入网站与离开网站时的访问时间,下面我来用js写几个简单的办法,各位朋友可参考。...

实例1

 代码如下 复制代码

<script type="text/javascript">
var second = 0;
var minute = 0;
var hour = 0;
window.setInterval("OnlineStayTime();", 1000);
function OnlineStayTime() {
second++;
if (second == 60) {
second = 0;
minute++;
}
if (minute == 60) {
minute = 0;
hour++;
}
window.status = "停留时间" + hour + ":" + minute + ":" + second;
}
</script>

实例2

 代码如下 复制代码

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
<HTML>
<Head>
<Meta http-equiv= "content-type " content= "text/html; charset=gb2312 ">
<Title> JavaScript计时器 </Title>
<H3> <Font color= "blue "> 主题:JavaScript计时器 </Font> </H3>
</Head>

<Body>
<Form name= "fm_Time " onSubmit= "0 ">
<Font size=5 color= "red "> <center> 显示您停留的时间 </Center> </Font> <P>
<HR size=3 color= "blue ">
现在时间: <P>
<Input type= "text " name= "t_spent " id= "t_spent " size=7>
</Form> <BR>
</HTML>
<Script language= "javascript ">
var time=1;
function show_secs(){
document.getElementById( 't_spent ').value=time+ '秒 ';
time++;
window.setTimeout( 'show_secs() ',1000);
}
show_secs();
</Script>

实例3

 

 代码如下 复制代码
 
<html>
<head>
<title>页面停留时间的统计方法</title>
</head>
<BODY onLoad="init(); window.setTimeout('show_secs()',1);">
<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 ()
{
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">您在本网页的停留时间:
<INPUT type="text" name="time_spent" size=7 onFocus="this.blur()">
</form>
</body>
</html>

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论