javascript精确统计网站访问量实例代码_javascript技

作者: 全球彩票官网下载  发布:2020-01-03

网址日常都有访问量总计工具,比较高效实用的工具数以万计,而且足够的高精度。实用javascript也足以轻巧的实现此成效,尽管未有互连网上常用的正确,可是确实也兑现了明确的功效,上面正是后生可畏段代码实例,感兴趣的爱侣能够参见一下:

/*** vlstat 浏览器统计脚本*/var statIdName = "vlstatId";var xmlHttp;/*** 设置cookieId*/function setCookie(c_name, value, expiredays) { var exdate = new Date(); exdate.setDate + expiredays); document.cookie = c_name + "=" + escape +  ? "" : ";expires=" + exdate.toGMTString + ";path=/;domain=cecb2b.com";}/*** 获取cookieId*/function getCookie { if (document.cookie.length > 0) { c_start = document.cookie.indexOf; if  { c_start = c_start + c_name.length + 1; c_end = document.cookie.indexOf; if  { c_end = document.cookie.length; } return unescape(document.cookie.substring; } } return "";}/*** 获取当前时间戳*/function getTimestamp() { var timestamp = Date.parse; return timestamp;}/*** 生成statId*/function genStatId() { var cookieId = getTimestamp(); cookieId = "vlstat" + "-" + cookieId + "-" + Math.round * 3000000000); return cookieId;}/*** 设置StatId*/function setStatId() { var cookieId = genStatId(); setCookie(statIdName, cookieId, 365);}/*** 获取StatId*/function getStatId() { var statId = getCookie; if (statId != null && statId.length > 0) { return statId; } else { setStatId; }}/*** 获取UA*/function getUA() { var ua = navigator.userAgent; if  { ua = ua.substring; } return ua;}/*** 获取浏览器类型*/function getBrower; if  != -1) { return "Maxthon"; } else if  != -1) { return "MSIE"; } else if  != -1) { return "Firefox"; } else if  != -1) { return "Chrome"; } else if  != -1) { return "Opera"; } else if  != -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; document.body.appendChild; frm.method = "POST"; return frm;}/*** 为form创建一个元素* * @param inputForm* @param elementName* @param elementValue* @return*/function createFormElement(frmInput, elementName, elementValue) { var element = document.createElement; element.setAttribute; element.setAttribute; element.setAttribute; element.setAttribute("value", elementValue); frmInput.appendChild; return element;}/*** 构造XMLHttpRequest对象* * @return*/function createXMLHttpRequest() { if  { xmlHttp = new ActiveXObject; } else if (window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); } }/*** url指定跳转页,data是要post的数据。func类似于函数指针* * @param url* @param data* @param func* @return*/function AjaxPost { var httpRequest = createHttpRequest { httpRequest.open; httpRequest.setRequestHeader("content-length", data.length); httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); httpRequest.send; httpRequest.onreadystatechange = function() { if (httpRequest.readyState == 4) { try { if (httpRequest.status == 200) { if  { // 这里可以调用想要的函数 func(httpRequest.responseText); } } } catch  { 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; var vlstatIPAddress = document.localName; var vlstatREFURL = encodeURIComponent; var vlstatURL = encodeURIComponent; var vlstatScreenX = screen.width; var vlstatScreenY = screen.height; var vlstatOS = getPlatform(); var vlstatBrower = getBrower(); var vlstatBrowerLanguage = getBrowerLanguage(); var vlstatPageTitle = encodeURIComponent; 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;xmlHttp.send;}

希望本文所述对我们学习javascript程序设计具备助于。

本文由全球彩票历史版本发布于全球彩票官网下载,转载请注明出处:javascript精确统计网站访问量实例代码_javascript技

关键词: