Web site access Statistics code implemented by JavaScript

Source: Internet
Author: User
Tags setcookie

JavaScript implements the website access statistics code:
Web sites generally have access statistics tools, more efficient and practical tools are various, and very accurate. Practical JavaScript can also be a simple implementation of this function, although not commonly used on the network of precision, but it does also achieve a certain function, the following is a code example, interested friends can refer to:

<script type= "Text/javascript" >/** * Vlstat Browser Statistics script*/varStatidname = "Vlstatid";varxmlHttp;/** * Set Cookieid*/functionSetcookie (c_name, value, expiredays) {varExdate =NewDate (); Exdate.setdate (Exdate.getdate ()+expiredays); Document.cookie= c_name + "=" + Escape (value) + ((Expiredays = =NULL) ? "": "; expires=" + exdate.togmtstring ()) + ";p ath=/;d omain=cecb2b.com";}/** * Get Cookieid*/functionGetCookie (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; }            returnunescape (document.cookie.substring (C_start, c_end)); }    }    return"";}/** * Get current timestamp*/functionGettimestamp () {vartimestamp = Date.parse (NewDate ()); returntimestamp;}/** * Generate Statid*/functionGenstatid () {varCookieid =Gettimestamp (); Cookieid= "Vlstat" + "-" + Cookieid + "-" + Math.Round (math.random () * 3000000000); returnCookieid;}/** * Set Statid*/functionSetstatid () {varCookieid =Genstatid (); Setcookie (Statidname, Cookieid,365);}/** * Get Statid*/functionGetstatid () {varStatid =GetCookie (statidname); if(Statid! =NULL&& statid.length > 0) {        returnStatid; } Else{Setstatid (); returnGetstatid (); }}/** * Get UA*/functionGetua () {varUA =navigator.useragent; if(Ua.length > 250) {UA= ua.substring (0, 250); }    returnUA;}/** * Get browser type*/functionGetbrower () {varUA =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"; }}/** * Get the browser language*/functionGetbrowerlanguage () {varLang =Navigator.browserlanguage; returnLang! =NULL&& lang.length > 0? Lang: "";}/** * Get operating system*/functionGetPlatform () {returnNavigator.platform;}/** * Get page title*/functionGetpagetitle () {returnDocument.title;}/** * Create a form* * @return*/functionCreatesubmitform () {varfrm = document.createelement ("form");    Document.body.appendChild (frm); Frm.method= "POST"; returnfrm;}/** * Create an element for form * * @param inputform* @param elementname* @param elementvalue* @return*/functioncreateformelement (Frminput, ElementName, elementvalue) {varelement = document.createelement ("Input"); Element.setattribute ("id", elementname); Element.setattribute ("Name", elementname); Element.setattribute ("Type", "hidden"); Element.setattribute ("Value", Elementvalue);    Frminput.appendchild (Element); returnelement;}/** * Construct XMLHttpRequest Object * * @return*/functioncreatexmlhttprequest () {if(window. ActiveXObject) {xmlHttp=NewActiveXObject (' Microsoft.XMLHTTP '); } Else if(window. XMLHttpRequest) {xmlHttp=NewXMLHttpRequest (); }  }/** * URL Specifies the jump page, data is to post. Func is similar to a function pointer * * @param url* @param data* @param func* @return*/functionajaxpost (URL, data, func) {varHttpRequest =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) {//you can call the desired function here.func (Httprequest.responsetext); }                    }                } Catch(e) {alert ("Error xmlhttprequest!"); }            }        }    } Else{alert ("Error initializing xmlhttprequest!"); }}functionVlstatinitle (Vlch, Vlch1, VLCH2, Vlch3) {varp; varVlstatch = Vlch! =NULL&& vlch.length > 0? Vlch: ""; varVlstatCH1 = vlch1! =NULL&& vlch1.length > 0? Vlch1: ""; varVlstatCH2 = vlch2! =NULL&& vlch2.length > 0? VLCH2: ""; varVlstatCH3 = Vlch3! =NULL&& vlch3.length > 0? VLCH3: ""; varVlstatcookieid =Getstatid (); varVlstatua =encodeURIComponent (Getua ()); varVlstatipaddress =Document.localname; varVlstatrefurl =encodeURIComponent (Document.referrer); varVlstaturl =encodeURIComponent (document.    URL); varVlstatscreenx =Screen.width; varVlstatscreeny =Screen.height; varVlstatos =GetPlatform (); varVlstatbrower =Getbrower (); varVlstatbrowerlanguage =Getbrowerlanguage (); varVlstatpagetitle =encodeURIComponent (Getpagetitle ()); varVlstataction = "index.php"; P= "Cookieid=" + Vlstatcookieid + "&ua=" + Vlstatua + "&ip=" + vlstatipaddress + "&refurl=" + vlstat Refurl + "&url=" + Vlstaturl + "&screenx=" + Vlstatscreenx + "&screeny=" +Vlstatscreeny+ "&os=" + Vlstatos + "&brower=" + vlstatbrower + "&browerlang=" +Vlstatbrowerlanguage+ "&title=" + vlstatpagetitle + "&ch=" + Vlstatch + "&ch1=" + vlstatCH1 + "&ch2=" +vlstatCH2+ "&ch3=" +vlstatCH3; varUrlgo = Vlstataction + "?" +p; Createxmlhttprequest (); Xmlhttp.open (' GET ', Urlgo); Xmlhttp.send (NULL);}</script>

The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=8012

For more information, refer to: http://www.softwhy.com/javascript/

Web site access Statistics code implemented by JavaScript

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.