Home  >  Article  >  Web Front-end  >  Javascript uses the Image object to implement buried point (number of clicks somewhere) statistics_javascript skills

Javascript uses the Image object to implement buried point (number of clicks somewhere) statistics_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:44:591909browse
Requirements: Count the number of clicks somewhere on the user page or the number of times executed to a certain point in the program
Features: Create multiple Image objects based on the actual situation, and the principle is who is free Who does things. Solve the problem of missing some buried points due to sending buried point data too quickly.
Implementation: (Note that the following code depends on jQuery)
Copy code The code is as follows:

var Statistic= {
arrImg:[],
log:function(from){
//If the parameter is empty, it will not be processed
if(typeof(from )=="undefined" || from=="") return;
var me=this,img,imgHandler,arrImg,len=0,index=-1;
arrImg=me.arrImg;
len=arrImg.length;
//Query available Image objects
for(var i=0;iif(arrImg[i].f==0){
index=i;
break;
}
}
//Retrieve or generate Image object
if(index==-1){
img=$(new Image());
arrImg.push({f:1,img:img});
index=(len==0?0:len);
}else{
img= arrImg[index].img;
}
//Mark the Image object as being in use
arrImg[index].f=1;
//Record the location of the used Image object
img.data("vid",index);
imgHandler = function(){
var vid=$(this).data("vid");
if(vid>=0){
arrImg[vid].f=0;
}
};
img.unbind().load(imgHandler).error(imgHandler);
var arr = [],ref ,url="http://z.ccccccc.com/beacon.gif?";
ref = document.referrer;
if (ref) {
ref=encodeURIComponent(ref);
}else{
ref='';
}
//Must strictly follow the following order: t, r, from, version
arr.push('t=' (new Date( )).getTime());
arr.push('r=' ref);
$(img).attr("src",url arr.join('&'));
}
};
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn