js ajax 传时间,js用img代替ajax js心跳 向服务器定时传送参数 主要计算用户在线时长...

html:

记录用户的在线时长

var Statistics_Website_logo ={

'Website_logo_title':'学而思',

'Website_logo_Theme':'教育行业',

'Website_logo_Company':'好未来'

};

OnlineTime.js:

/***

****2015.1.4 img代替ajax心跳 主要计算用户在线时长****

***/

var xue = xue || {};

xue.statistics = xue.statistics || {};

xue.statistics.TimerFunction = null;//定时器函数

xue.statistics.RefreshTime = 5000;//定时器刷新时间

xue.statistics.Domain = document.domain;//域名

xue.statistics.URL = window.location.href;//URL

xue.statistics.Title = document.title;//页面标题

xue.statistics.Resolution = (window.screen.height)+'&&'+(window.screen.width);//分辨率

xue.statistics.ColorDepth = window.screen.colorDepth;//颜色深度

xue.statistics.Referrer = document.referrer;//Referrer

xue.statistics.ClientLanguage = navigator.language;//客户端语言

xue.statistics.AppName = navigator.appName;//客户端浏览器名称

xue.statistics.AppVersion = navigator.appVersion;//客户端浏览器版本号

xue.statistics.Timestamp = new Date().getTime();//页面刷新时间戳

xue.statistics.RefreshTimes = 0;//定时器响应的次数

xue.statistics.ImgAjax = document.createElement("img");

xue.statistics.ImgAjax.id="ImgOnlineTime";

xue.statistics.ImgAjax.style.width = "0";

xue.statistics.ImgAjax.style.height = "0";

document.body.appendChild(xue.statistics.ImgAjax);

/****

***设置cookie和获取cookie***

***/

xue.statistics.getsec = function(str){

var str1=str.substring(1,str.length)*1;

var str2=str.substring(0,1);

if (str2=="s"){

return str1*1000;

}else if (str2=="h"){

return str1*60*60*1000;

}else if (str2=="d"){

return str1*24*60*60*1000;

}

}

xue.statistics.setCookie = function (name,value,time){

var strsec = this.getsec(time);

var exp = new Date();

exp.setTime(exp.getTime() + strsec*1);

document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString()+";path=/;domain=.xueersi.com";

}

xue.statistics.getCookie = function(name){

var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");

if(arr=document.cookie.match(reg))

return (arr[2]);

else

return null;

}

xue.statistics.randomNum = function(randomNum){

this.Random="";

for(var i=0;i

this.Random+=Math.floor(Math.random()*10);

return this.Random;

}

//用户自定义的网站标识

xue.statistics.Websitelogo = '';

var Statistics_Website_logo;

try{

for (var Key in Statistics_Website_logo){

xue.statistics.Websitelogo =xue.statistics.Websitelogo+'&'+''+Key+'='+Statistics_Website_logo[Key]+'';

}

}catch(e){

xue.statistics.Websitelogo = '';

}

/****

***统计页面函数***

***/

xue.statistics.AjaxOnlineTime = function () {

this.RefreshTimes++;

this.Random = this.randomNum(5) + this.Timestamp;

this.setCookie("xue_stat",this.Random,"d1000000000000000");//设置客户标识

this.Visitorslogo = this.getCookie('xue_stat');

this.Data = 'http://xeslog.xesv5.com/?Domain='+this.Domain+'&URL='+this.URL+'&Title='+this.Title+'&Resolution='+this.Resolution+'&ColorDepth='+this.ColorDepth+'&Referrer='+this.Referrer+'&ClientLanguage='+this.ClientLanguage+'&AppName='+this.AppName+'&AppVersion='+this.AppVersion+'&Timestamp='+this.Timestamp+'&xue_stat='+this.Visitorslogo+''+this.Websitelogo+'';

document.getElementById('ImgOnlineTime').src = this.Data;

};

window.onload = function(){

// if(navigator.userAgent.indexOf('WebKit')>0){

xue.statistics.TimerFunction = window.setInterval("xue.statistics.AjaxOnlineTime()", xue.statistics.RefreshTime);//定时器每5s刷新一次

//}

window.οnblur=function(){

window.clearInterval(xue.statistics.TimerFunction);

window.οnfοcus=function(){

//window.clearInterval(xue.statistics.TimerFunction);

xue.statistics.TimerFunction = window.setInterval("xue.statistics.AjaxOnlineTime()", xue.statistics.RefreshTime);//定时器每5s刷新一次

};

};

};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值