废话不多说了,直接给大家贴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(math.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.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); } </script>
下面在给大家分享一段代码实例-js 精确统计网站访问量程序
/** * 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(math.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.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); }
更多javascript实现的网站访问量统计代码。
