JS using img Instead of Ajax JS Heartbeat to the server timing transfer parameters mainly calculate the user's online length

Source: Internet
Author: User
Tags setcookie

Html:

<!doctype html>
<meta charset= "Utf-8" >
<title> record the user's online duration </title>

<body>
</body>
<script type= "Text/javascript" >
var Statistics_website_logo ={
' Website_logo_title ': ' Learning and thinking ',
' Website_logo_theme ': ' Education industry ',
' Website_logo_company ': ' Good Future '
};
</script>
<script type= "Text/javascript" src= "Js/onlinetime.js" ></script>

Onlinetime.js:

/***
2015.1.4 img Instead of AJAX heartbeat main calculation user Online duration * * * *
***/

var xue = Xue | | {};
Xue.infocount = Xue.infocount | | {};
xue.infoCount.TimerFunction = null;//Timer function
Xue.infoCount.RefreshTime = 5000;//Timer Refresh Time
Xue.infoCount.Domain = document.domain;//Domain name
Xue.infoCount.URL = document. Url;//url
Xue.infoCount.Title = document.title;//Page title
Xue.infoCount.Resolution = (window.screen.height) + ' && ' + (window.screen.width);//Resolution
xue.infoCount.ColorDepth = window.screen.colordepth;//Color depth
Xue.infoCount.Referrer = Document.referrer;//referrer
Xue.infoCount.ClientLanguage = navigator.language;//Client language
Xue.infoCount.AppName = navigator.appname;//client browser name
xue.infoCount.AppVersion = navigator.appversion;//client browser version number
Xue.infoCount.Timestamp = new Date (). GetTime ();//page refresh timestamp
Xue.infoCount.RefreshTimes = number of times the 0;//timer responds

Xue.infoCount.ImgAjax = document.createelement ("img");
Xue.infocount.imgajax.id= "Imgonlinetime";
Xue.infoCount.ImgAjax.style.width = "0";
Xue.infoCount.ImgAjax.style.height = "0";
Document.body.appendChild (Xue.infoCount.ImgAjax);
/****
Set cookies and get cookie***
***/
xue.infoCount.getsec = function (str) {
var str1=str.substring (1,str.length) * *;
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.infoCount.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 ();
}

Xue.infoCount.getCookie = function (name) {
var arr,reg=new RegExp ("(^|)" +name+ "= ([^;] *)(;|$)");

if (Arr=document.cookie.match (REG))

Return (arr[2]);
Else
return null;
}
User-defined site identity
Xue.infoCount.Websitelogo = ";
var Statistics_website_logo;

if (Statistics_website_logo) {
for (Var Key in Statistics_website_logo) {
Xue.infoCount.Websitelogo =xue.infocount.websitelogo+ ' & ' + ' +key+ ' = ' +statistics_website_logo[key]+ ';
}
}else{
Xue.infoCount.Websitelogo = ";
}
/****
Statistics page Functions * * *
***/
Xue.infoCount.AjaxOnlineTime = function () {

This. refreshtimes++;

This.setcookie ("Visitorslogo", "Xueersi", "d1000000000000000");//set up customer ID
This. Visitorslogo = This.getcookie (' Visitorslogo ');
if (this. Visitorslogo) {

This. Visitorslogo = ' 1 '
}else{

This. Visitorslogo = ' 0 '
}


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+ ' &visitorslogo= ' +this. Visitorslogo+ ' +this. Websitelogo+ ";

document.getElementById (' Imgonlinetime '). SetAttribute ("src", this.) Data);

};

Xue.infoCount.TimerFunction = Window.setinterval ("Xue.infoCount.AjaxOnlineTime ()", xue.infoCount.RefreshTime);// Timer refreshes every 5s

Window.onload = function () {

Window.onfocus=function () {
Window.clearinterval (xue.infoCount.TimerFunction);
Xue.infoCount.TimerFunction = Window.setinterval ("Xue.infoCount.AjaxOnlineTime ()", xue.infoCount.RefreshTime);// Timer refreshes every 5s
};

Window.onblur=function () {
Window.clearinterval (xue.infoCount.TimerFunction);
};
};




JS using img Instead of Ajax JS Heartbeat to the server timing transfer parameters mainly calculate the user's online length

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.