<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>无标题页</title>
<script language="Javascript">
pageOpenTime = new Date();//定义打开网页的时间
function goodbye()
{
pageCloseTime = new Date();//定义关闭网页的时间
minutes = (pageCloseTime.getMinutes() - pageOpenTime.getMinutes());
seconds = (pageCloseTime.getSeconds() - pageOpenTime.getSeconds());
time = (seconds + (minutes * 60));
alert('总共停留了' + time + '秒,一路走好!');
}
</script>
</head>
<body οnunlοad="goodbye()">
------------------------------
<script type="text/JavaScript"></script><script src="http://a.alimama.cn/inf.js" type="text/javascript"></script>
<!--文章内容广告结束-->分析用户行为时,某网页停留时间可能会是个可参考的数据 由后台分析函数取一个合理值作为在线时间
每xxxxx毫秒检测一次是否在线,
TR_COUNT次之后设定改用户为假死状态(即不在当前页面活动,afk..)
当页面关闭时把停留时间送出,
/**//* ----------------------------------------------------------------------------
* Script Name: online.js
* Last Modified: 2008-4-13 22:25
* Author: meyu
* Copyright (c) 2008
* Purpose: 跟踪在线时间
* ----------------------------------------------------------------------------*/
|
用图片方式.欺骗用户的眼睛. 秒的那个gif,每1秒变一次,10秒的那个图每10秒变一次.. 变成1,2,3,,....这样便形成了10几秒,20几秒的图片..... 高.
-----------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>test</title>
<SCRIPT LANGUAGE=javascript>function getXMLHTTPObj(){
var xmlHttp=null;
try{xmlHttp=new XMLHttpRequest();}
catch (MSIEx){
try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
catch (e){
try{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
catch(e){alert('您的浏览器不支持AJAX!');}
}
}
return xmlHttp;
}var sTimer=0, eTimer=0, period=0
window.οnlοad=function(){ sTimer=new Date().getTime();}//页面加载完成即开始计时
window.οnbefοreunlοad=function(){ //离开页面结束计时(包括刷新;如果去掉刷新需要做附加判断)
eTimer=new Date().getTime();
period=(eTimer-sTimer);//这个是停留时间(毫秒)
//AJAX到后台写库
var url="ajax.asp?period="+period+"&t="+new Date().getTime();
var x = getXMLHTTPObj(), ret=0, msg='';
x.open('POST',url,false)
x.send(null);
ret=x.responseText;
x=null;
var msg=ret==0?'写库失败':'写库成功'
alert('停留时间:'+ret+'秒;'+msg)
}
</SCRIPT>
</head>
<body>
测试停留时间测试停留时间测试停留时间测试停留时间测试停留时间测试停留时间<br>
测试停留时间测试停留时间测试停留时间测试停留时间测试停留时间测试停留时间<br>
测试停留时间测试停留时间测试停留时间测试停留时间测试停留时间测试停留时间<br>
</body>
</html>
后台:ajax.asp
<% period = Request.QueryString( " period " ) if period = "" then Response.Write " 0 " Response.End else period = formatnumber (period / 1000 , 2 , - 1 ) end if sql = " INSERT INTO 表(停留时间字段名) VALUES(' " & period & " ') " conn.execute(sql) if err then Response.Write " 0 " else Response.Write period end if %>
-----------------------------------------