熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

JS 精確統計網站訪問量的實例代碼

2022-06-13   來源: JSP教程 
這篇文章介紹了JS精確統計網站訪問量的實例代碼有需要的朋友可以參考一下   復制代碼 代碼如下:

  
/**
 * vlstat 浏覽器統計腳本
 */
var statIdName = "vlstatId";
var xmlHttp;
/**
 * 設置cookieId
 */
function setCookie(c_name value expiredays) {
    var exdate = new Date();
    exdatesetDate(exdategetDate() + expiredays);
    documentcookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdatetoGMTString()) + ";path=/;domain=cecbbcom";
}
/**
 * 獲取cookieId
 */
function getCookie(c_name) {
    if (documentcookielength > ) {
        c_start = documentcookieindexOf(c_name + "=");
        if (c_start != ) {
            c_start = c_start + c_namelength + ;
            c_end = documentcookieindexOf(";" c_start);
            if (c_end == ) {
                c_end = documentcookielength;
            }
            return unescape(documentcookiesubstring(c_start c_end));
        }
    }
    return "";
}
/**
 * 獲取當前時間戳
 */
function getTimestamp() {
    var timestamp = Dateparse(new Date());
    return timestamp;
}
/**
 * 生成statId
 */
function genStatId() {
    var cookieId = getTimestamp();
    cookieId = "vlstat" + "" + cookieId + "" + Mathround(Mathrandom() * );
    return cookieId;
}
/**
 * 設置StatId
 */
function setStatId() {
    var cookieId = genStatId();
    setCookie(statIdName cookieId );
}
/**
 * 獲取StatId
 */
function getStatId() {
    var statId = getCookie(statIdName);
    if (statId != null && statIdlength > ) {
        return statId;
    } else {
        setStatId();
        return getStatId();
    }
}
/**
 * 獲取UA
 */
function getUA() {
    var ua = navigatoruserAgent;
    if (ualength > ) {
        ua = uasubstring( );
    }
    return ua;
}
/**
 * 獲取浏覽器類型
 */
function getBrower() {
    var ua = getUA();
    if (uaindexOf("Maxthon") != ) {
        return "Maxthon";
    } else if (uaindexOf("MSIE") != ) {
        return "MSIE";
    } else if (uaindexOf("Firefox") != ) {
        return "Firefox";
    } else if (uaindexOf("Chrome") != ) {
        return "Chrome";
    } else if (uaindexOf("Opera") != ) {
        return "Opera";
    } else if (uaindexOf("Safari") != ) {
        return "Safari";
    } else {
        return "ot";
    }
}
/**
 * 獲取浏覽器語言
 */
function getBrowerLanguage() {
    var lang = navigatorbrowserLanguage;
    return lang != null && langlength > ? lang : "";
}
/**
 * 獲取操作系統
 */
function getPlatform() {
    return navigatorplatform;
}
/**
 * 獲取頁面title
 */
function getPageTitle() {
    return documenttitle;
}
/**
 * 創建一個form
 *
 * @return
 */
function createSubmitForm() {
    var frm = documentcreateElement("form");
    documentbodyappendChild(frm);
    frmmethod = "POST";
    return frm;
}
/**
 * 為form創建一個元素
 *
 * @param inputForm
 * @param elementName
 * @param elementValue
 * @return
 */
function createFormElement(frmInput elementName elementValue) {
    var element = documentcreateElement("input");
    elementsetAttribute("id" elementName);
    elementsetAttribute("name" elementName);
    elementsetAttribute("type" "hidden");
    elementsetAttribute("value" elementValue);
    frmInputappendChild(element);
    return element;
}
/**
 * 構造XMLHttpRequest對象
 *
 * @return
 */
function createXMLHttpRequest() { 
 if (windowActiveXObject) { 
  xmlHttp = new ActiveXObject(MicrosoftXMLHTTP); 
 } else if (windowXMLHttpRequest) { 
  xmlHttp = new XMLHttpRequest(); 
 } 
}
/**
 * url指定跳轉頁data是要post的數據func類似於函數指針
 *
 * @param url
 * @param data
 * @param func
 * @return
 */
function AjaxPost(url data func) {
    var httpRequest = createHttpRequest();
    if (httpRequest) {
        ("POST" url true);
        ("contentlength" datalength);
        ("ContentType" "application/xwwwformurlencoded");
        (data);
        () {
            if {
                try {
                    if {
                        if (func) {
                            // 這裡可以調用想要的函數
                            func(
                        }
                    }
                } catch (e) {
                    alert("Error XMLHttpRequest!");
                }
            }
        }
    } else {
        alert("Error initializing XMLHttpRequest!");
    }
}
function vlstatInitLE(vlch vlch vlch vlch) {
    var p;
    var vlstatCH = vlch != null && vlchlength > ? vlch : "";
    var vlstatCH = vlch != null && vlchlength > ? vlch : "";
    var vlstatCH = vlch != null && vlchlength > ? vlch : "";
    var vlstatCH = vlch != null && vlchlength > ? vlch : "";
    var vlstatCookieId = getStatId();
    var vlstatUA = encodeURIComponent(getUA());
    var vlstatIPAddress = documentlocalName;
    var vlstatREFURL = encodeURIComponent(documentreferrer);
    var vlstatURL = encodeURIComponent(documentURL);
    var vlstatScreenX = screenwidth;
    var vlstatScreenY = screenheight;
    var vlstatOS = getPlatform();
    var vlstatBrower = getBrower();
    var vlstatBrowerLanguage = getBrowerLanguage();
    var vlstatPageTitle = encodeURIComponent(getPageTitle());
    var vlstatAction = "indexphp";
    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 + "&ch=" + vlstatCH + "&ch=" + vlstatCH
            + "&ch=" + vlstatCH;
    var urlGo = vlstatAction + "?" + p;
    createXMLHttpRequest();
 xmlHttpopen(GET urlGo);
 xmlHttpsend(null);
}


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20528.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.