JavaScript
发布时间:2022-04-16 发布网站:大佬教程 code.js-code.com
大佬教程收集整理的这篇文章主要介绍了javascript实现的网站访问量统计代码,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
网站一般都有访问量统计工具,比较高效实用的工具多种多样,并且非常的精确。实用javascript也可以简单的实现此功能,尽管没有网络上常用的精确,不过的确也实现了一定的功能,下面就是一段代码实例,感兴趣的朋友可以参考一下:
废话不多说了,直接给大家贴js代码了。
<script type="text/javascript">
/
**
- vlstat 浏览器统计脚本
*/
var statIdName = "vlstatId";
var xmlhttp;
/**
- 设置cookiEID
*/
function setCookie(c_name,value,expiredays) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + expiredays);
document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString()) + ";path=/;domain=cecb2b.com";
}
/**
- 获取cookiEID
*/
function getCookie(c_Name) {
if (document.cookie.length > 0) {
c_start = document.cookie.indexOf(c_name + "=");
if (c_start != -1) {
c_start = c_start + c_name.length + 1;
c_end = document.cookie.indexOf(";",c_start);
if (c_end == -1) {
c_end = document.cookie.length;
}
return unescape(document.cookie.subString(c_start,c_end));
}
}
return "";
}
/**
- 获取当前时间戳
*/
function gettimestamp() {
var timestamp = Date.parse(new Date());
return timestamp;
}
/**
- 生成statId
/
function genStatId() {
var cookiEID = gettimestamp();
cookiEID = "vlstat" + "-" + cookiEID + "-" + Math.round(R_61_11845@ath.random() 3000000000);
return cookiEID;
}
/**
- 设置StatId
*/
function setStatId() {
var cookiEID = genStatId();
setCookie(statIdName,cookiEID,365);
}
/**
- 获取StatId
*/
function getStatId() {
var statId = getCookie(statIdName);
if (statId != null && statId.length > 0) {
return statId;
} else {
setStatId();
return getStatId();
}
}
/**
- 获取UA
*/
function getUA() {
var ua = navigator.userAgent;
if (ua.length > 250) {
ua = ua.subString(0,250);
}
return ua;
}
/**
- 获取浏览器类型
*/
function getBrower() {
var ua = getUA();
if (ua.indexOf("Maxthon") != -1) {
return "Maxthon";
} else if (ua.indexOf("MSIE") != -1) {
return "MSIE";
} else if (ua.indexOf("Firefox") != -1) {
return "Firefox";
} else if (ua.indexOf("Chrome") != -1) {
return "Chrome";
} else if (ua.indexOf("Opera") != -1) {
return "Opera";
} else if (ua.indexOf("Safari") != -1) {
return "Safari";
} else {
return "ot";
}
}
/**
- 获取浏览器语言
*/
function getBrowerLanguage() {
var lang = navigator.browserLanguage;
return lang != null && lang.length > 0 ? lang : "";
}
/**
- 获取操作系统
*/
function getPlatform() {
return navigator.platform;
}
/**
- 获取页面title
*/
function getPagetitle() {
return document.title;
}
/**
- 创建一个form
-
- @return
*/
function createSubmitForm() {
var frm = document.createElement("form");
document.body.appendChild(frm);
frm.method = "POST";
return frm;
}
/**
- 为form创建一个元素
-
- @param inputForm
- @param elementName
- @param elementValue
- @return
*/
function createFormElement(frmInput,elementName,elementvalue) {
var element = document.createElement("input");
element.setAttribute("id",elementName);
element.setAttribute("name",elementName);
element.setAttribute("type","hidden");
element.setAttribute("value",elementvalue);
frmInput.appendChild(element);
return element;
}
/**
- 构造XMLhttprequest对象
-
- @return
*/
function createXMLhttprequest() {
if (window.ActiveXObject) {
xmlhttp = new ActiveXObject('Microsoft.XMLhttp');
} else if (window.XMLhttprequest) {
xmlhttp = new XMLhttprequest();
}
}
/**
- url指定跳转页,data是要post的数据。func类似于函数指针
-
- @param url
- @param data
- @param func
- @return
*/
function AjaxPost(url,data,funC) {
var httprequest = createhttprequest();
if (httprequest) {
httprequest.open("POST",url,truE);
httprequest.setrequestHeader("content-length",data.length);
httprequest.setrequestHeader("Content-Type","application/x-www-form-urlencoded");
httprequest.send(data);
httprequest.onreadystatechange = function() {
if (httprequest.readyState == 4) {
try {
if (httprequest.status == 200) {
if (funC) {
// 这里可以调用想要的函数
func(httprequest.responseText);
}
}
} catch (E) {
alert("Error XMLhttprequest!");
}
}
}
} else {
alert("Error initializing XMLhttprequest!");
}
}
function vlstaTinitLE(vlch,vlch1,vlch2,vlch3) {
var p;
var vlstatCH = vlch != null && vlch.length > 0 ? vlch : "";
var vlstatCH1 = vlch1 != null && vlch1.length > 0 ? vlch1 : "";
var vlstatCH2 = vlch2 != null && vlch2.length > 0 ? vlch2 : "";
var vlstatCH3 = vlch3 != null && vlch3.length > 0 ? vlch3 : "";
var vlstatCookiEID = getStatId();
var vlstatUA = encodeURIComponent(getUA());
var vlstatIpaddress = document.localName;
var vlstatREFURL = encodeURIComponent(document.referrer);
var vlstatURL = encodeURIComponent(document.URL);
var vlstatScreenX = screen.width;
var vlstatScreenY = screen.height;
var vlstatOS = getPlatform();
var vlstatBrower = getBrower();
var vlstatBrowerLanguage = getBrowerLanguage();
var vlstatPagetitle = encodeURIComponent(getPagetitle());
var vlstatAction = "index.php";
p = "cookiEID=" + vlstatCookiEID + "&ua=" + vlstatUA + "&ip=" + vlstatIpaddress + "&refurl="
- vlstatREFURL + "&url=" + vlstatURL + "&screenX=" + vlstatScreenX + "&screenY=" + vlstatScreenY
- "&os=" + vlstatOS + "&brower=" + vlstatBrower + "&browerLang=" + vlstatBrowerLanguage
- "&title=" + vlstatPagetitle + "&ch=" + vlstatCH + "&ch1=" + vlstatCH1 + "&ch2=" + vlstatCH2
- "&ch3=" + vlstatCH3;
var urlGo = vlstatAction + "?" + p;
createXMLhttprequest();
xmlhttp.open('GET',urlGo);
xmlhttp.send(null);
}
@H_673_261@下面在给大家分享一段代码实例-JS 精确统计网站访问量程序@H_306_262@
**
vlstat 浏览器统计脚本
*/
var statIdName = "vlstatId";
var xmlhttp;
/**
设置cookiEID
*/
function setCookie(c_name,expiredays) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + expiredays);
document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString()) + ";path=/;domain=cecb2b.com";
}
/**
获取cookiEID
*/
function getCookie(c_Name) {
if (document.cookie.length > 0) {
c_start = document.cookie.indexOf(c_name + "=");
if (c_start != -1) {
c_start = c_start + c_name.length + 1;
c_end = document.cookie.indexOf(";",c_start);
if (c_end == -1) {
c_end = document.cookie.length;
}
return unescape(document.cookie.subString(c_start,c_end));
}
}
return "";
}
/**
获取当前时间戳
*/
function gettimestamp() {
var timestamp = Date.parse(new Date());
return timestamp;
}
/**
生成statId
/
function genStatId() {
var cookiEID = gettimestamp();
cookiEID = "vlstat" + "-" + cookiEID + "-" + Math.round(R_61_11845@ath.random() 3000000000);
return cookiEID;
}
/**
设置StatId
*/
function setStatId() {
var cookiEID = genStatId();
setCookie(statIdName,365);
}
/**
获取StatId
*/
function getStatId() {
var statId = getCookie(statIdName);
if (statId != null && statId.length > 0) {
return statId;
} else {
setStatId();
return getStatId();
}
}
/**
获取UA
*/
function getUA() {
var ua = navigator.userAgent;
if (ua.length > 250) {
ua = ua.subString(0,250);
}
return ua;
}
/**
获取浏览器类型
*/
function getBrower() {
var ua = getUA();
if (ua.indexOf("Maxthon") != -1) {
return "Maxthon";
} else if (ua.indexOf("MSIE") != -1) {
return "MSIE";
} else if (ua.indexOf("Firefox") != -1) {
return "Firefox";
} else if (ua.indexOf("Chrome") != -1) {
return "Chrome";
} else if (ua.indexOf("Opera") != -1) {
return "Opera";
} else if (ua.indexOf("Safari") != -1) {
return "Safari";
} else {
return "ot";
}
}
/**
获取浏览器语言
*/
function getBrowerLanguage() {
var lang = navigator.browserLanguage;
return lang != null && lang.length > 0 ? lang : "";
}
/**
获取操作系统
*/
function getPlatform() {
return navigator.platform;
}
/**
获取页面title
*/
function getPagetitle() {
return document.title;
}
/**
创建一个form
@return
*/
function createSubmitForm() {
var frm = document.createElement("form");
document.body.appendChild(frm);
frm.method = "POST";
return frm;
}
/**
为form创建一个元素
@param inputForm
@param elementName
@param elementValue
@return
*/
function createFormElement(frmInput,elementvalue) {
var element = document.createElement("input");
element.setAttribute("id",elementName);
element.setAttribute("name",elementName);
element.setAttribute("type","hidden");
element.setAttribute("value",elementvalue);
frmInput.appendChild(element);
return element;
}
/**
构造XMLhttprequest对象
@return
*/
function createXMLhttprequest() {
if (window.ActiveXObject) {
xmlhttp = new ActiveXObject('Microsoft.XMLhttp');
} else if (window.XMLhttprequest) {
xmlhttp = new XMLhttprequest();
}
}
/**
url指定跳转页,data是要post的数据。func类似于函数指针
@param url
@param data
@param func
@return
*/
function AjaxPost(url,funC) {
var httprequest = createhttprequest();
if (httprequest) {
httprequest.open("POST",truE);
httprequest.setrequestHeader("content-length",data.length);
httprequest.setrequestHeader("Content-Type","application/x-www-form-urlencoded");
httprequest.send(data);
httprequest.onreadystatechange = function() {
if (httprequest.readyState == 4) {
try {
if (httprequest.status == 200) {
if (funC) {
// 这里可以调用想要的函数
func(httprequest.responseText);
}
}
} catch (E) {
alert("Error XMLhttprequest!");
}
}
}
} else {
alert("Error initializing XMLhttprequest!");
}
}
function vlstaTinitLE(vlch,vlch3) {
var p;
var vlstatCH = vlch != null && vlch.length > 0 ? vlch : "";
var vlstatCH1 = vlch1 != null && vlch1.length > 0 ? vlch1 : "";
var vlstatCH2 = vlch2 != null && vlch2.length > 0 ? vlch2 : "";
var vlstatCH3 = vlch3 != null && vlch3.length > 0 ? vlch3 : "";
var vlstatCookiEID = getStatId();
var vlstatUA = encodeURIComponent(getUA());
var vlstatIpaddress = document.localName;
var vlstatREFURL = encodeURIComponent(document.referrer);
var vlstatURL = encodeURIComponent(document.URL);
var vlstatScreenX = screen.width;
var vlstatScreenY = screen.height;
var vlstatOS = getPlatform();
var vlstatBrower = getBrower();
var vlstatBrowerLanguage = getBrowerLanguage();
var vlstatPagetitle = encodeURIComponent(getPagetitle());
var vlstatAction = "index.php";
p = "cookiEID=" + vlstatCookiEID + "&ua=" + vlstatUA + "&ip=" + vlstatIpaddress + "&refurl="
- vlstatREFURL + "&url=" + vlstatURL + "&screenX=" + vlstatScreenX + "&screenY=" + vlstatScreenY
- "&os=" + vlstatOS + "&brower=" + vlstatBrower + "&browerLang=" + vlstatBrowerLanguage
- "&title=" + vlstatPagetitle + "&ch=" + vlstatCH + "&ch1=" + vlstatCH1 + "&ch2=" + vlstatCH2
- "&ch3=" + vlstatCH3;
var urlGo = vlstatAction + "?" + p;
createXMLhttprequest();
xmlhttp.open('GET',urlGo);
xmlhttp.send(null);
}
大佬总结
以上是大佬教程为你收集整理的javascript实现的网站访问量统计代码全部内容,希望文章能够帮你解决javascript实现的网站访问量统计代码所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。