首頁 >web前端 >js教程 >JS 精確統計網站訪問量的實例程式碼_javascript技巧

JS 精確統計網站訪問量的實例程式碼_javascript技巧

WBOY
WBOY原創
2016-05-16 17:29:521084瀏覽
複製程式碼 程式碼如下:

/**
* 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 "=エスケープ(value) ((expiredays == null) ? "" : ";expires=" exdate.toGMTString()) ";path=/;domain=cecb2b.com";
}
/**
* cookieId を取得します
*/
関数 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 lang = navigator.browserLanguage;
return lang != null && lang.length > 0 ? lang : "";
}
/**
* オペレーティング システムを入手
*/
function getPlatform() {
return navigator.platform;
}
/**
* ページタイトルを取得
* /
function getPageTitle() {
return document.title;
}
/**
* フォームを作成します
*
* @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
 * @param elementValue
 */
function createFormElement(frmInput, elementName, elementValue) {
    var element = document.createElement("input");
elementName);
    element.setAttribute("name", elementName);
    element.setAttribute("type", "hidden");
frmInput.appendChild(element);
    return element;
}
/**
 * 建構XMLHttpRequest物件
 *
 * @return
 */
function createXMLHttpRequest() {p = new ActiveXObject('Microsoft.XMLHTTP'); 
 } else if (window.XMLHttpRequest) { 
  xmlHttp = new XMLHttpRequest(); 
 } 
}
/**
 * url指定跳轉頁,data是要post的資料。func 模仿函數指標
 *
 * @param url
 * @param data
 * @param func
 * @return
 */
func) {
    var httpRequest = createHttpRequest();
    if (httpRequest) {
       -length" , data.length);
        httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   function ( ) {
            if (httpRequest.readyState == 4) {
                if (httpRequest.status == 200) {
                                // 這裡呼叫可以想要的函數
                           func(httpRequest.responseText);
                    }
                   }
                } catch (e) {
                   alert("XMLHttpRequest 錯誤!");
                }
}
        }
    } else {
       alert("初始化XMLHttpRequest 時出錯! , 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());
  URIComponent(document.referrer) ;
    var vlstatURL =encodeURIComponent(document.URL);
    var vlstatScreenX = screen.width;
 ion );
    var vlstatBrower = getBrower();
    var vlstatBrowerLanguage = getBrowerLanguage();
    var vlstatPageTitle =encodeURIComponent(getPageTitle());           」&url=「vlstatURL」&screenX=「vlstatScreenXvl&screenY=「vlstatURL」&screenX=「vlstatScreenXvlstatScreenY statOS”&brower=“vlstatBrower”&browerLang= “vlstatBrowerLang ”瓦格
            "&title=" vlstatPageTitle "&ch=" vlstatCH "&ch1=" vlstatCH1 "&ch2=" vlstatCH2 createXMLHttpRequest ();
 xmlHttp.open('GET', urlGo);
 xmlHttp.send(null);
}

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn