JavaScript implementation of Web site traffic statistics code _javascript tips

Source: Internet
Author: User
Tags getdate http request setcookie

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

Nonsense not much said, directly to everyone paste JS code.


<script type= "Text/javascript" >/** * Vlstat Browser Statistic script * * var statidname = "Vlstatid";
var xmlHttp;
 /** * Set 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 ()) +";p ath=/;d omain=cecb2b.com ";} /** * Get 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 "";}
 /** * Gets the current timestamp/function Gettimestamp () {var timestamp = Date.parse (new Date ());
return timestamp;
 /** * Generate Statid/function Genstatid () {var cookieid = Gettimestamp (); Cookieid = "Vlstat" + "-" + Cookieid + "-" + Math.Round (math.random () * 3000000000);
return Cookieid;
 /** * Set Statid/function Setstatid () {var cookieid = Genstatid ();
Setcookie (Statidname, Cookieid, 365);
 /** * Get Statid/function Getstatid () {var statid = GetCookie (statidname);
 if (Statid!= null && statid.length > 0) {return statid;
  else {Setstatid ();
 return Getstatid ();
 }/** * Get UA/function Getua () {var ua = navigator.useragent;
 if (Ua.length >) {ua = ua.substring (0, 250);
Return UA;
 /** * Get Browser type/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 '; }/** * Get the browser language * * * function Getbrowerlanguage () {var lang = navigator.browserlanguage; return lang!= null && lang.length > 0?
Lang: "";} /** * Get OS/function GetPlatform () {return navigator.platform;}/** * Get page title/function Getpagetitle () {retur
n Document.title;
 /** * Create a form * * @return/function Createsubmitform () {var frm = document.createelement ("form");
 Document.body.appendChild (frm);
 Frm.method = "POST";
return frm; /** * Create an element for form * * @param inputform * @param elementname * @param elementvalue * @return/function Createformeleme
 NT (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; /** * Constructs XMLHttpRequest Object * * @return/function createxmlhttprequest () {if (window). ActiveXObject) {xmlHttp = new ACtivexobject (' microsoft.xmlhttp '); else if (window. 
XMLHttpRequest) {xmlHttp = new XMLHttpRequest (); The/** * URL specifies the jump page, and data is the one to post.  Func similar to function pointer * * @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)
      (= =) {if (func) {///Here you can call the desired function 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= "+ V
 Lstatch + "&ch1=" + vlstatCH1 + "&ch2=" + vlstatCH2 + "&ch3=" + vlstatCH3;
 var Urlgo = vlstataction + "?" + P;
Createxmlhttprequest ();
Xmlhttp.open (' Get ', Urlgo);
Xmlhttp.send (NULL); } </script>

below to share a piece of code instance-js accurate statistics Web site Access Program

/** * Vlstat Browser Statistics Script * * var statidname = "Vlstatid"; 
var xmlHttp; 
  /** * Set 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 () + ";p ath=/;d omain=cecb2b.com"; /** * Get Cookieid/function GetCookie (c_name) {if (Document.cookie.length > 0) {c_start = document.c 
    Ookie.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 ""; 
  /** * Gets the current timestamp/function Gettimestamp () {var timestamp = Date.parse (new Date ()); 
return timestamp; /** * Generate Statid/function Genstatid () {var cookieiD = Gettimestamp (); 
  Cookieid = "Vlstat" + "-" + Cookieid + "-" + Math.Round (math.random () * 3000000000); 
return Cookieid; 
  /** * Set Statid/function Setstatid () {var cookieid = Genstatid (); 
Setcookie (Statidname, Cookieid, 365); 
  /** * Get Statid/function Getstatid () {var statid = GetCookie (statidname); 
  if (Statid!= null && statid.length > 0) {return statid; 
    else {Setstatid (); 
  return Getstatid (); 
  }/** * Get UA/function Getua () {var ua = navigator.useragent; 
  if (Ua.length >) {ua = ua.substring (0, 250); 
Return UA; 
  /** * Get Browser type/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 '; 
  }/** * Get browser language/function Getbrowerlanguage () {var lang = navigator.browserlanguage; return lang!= null && lang.length > 0? 
Lang: ""; 
/** * Get operating system * * Function GetPlatform () {return navigator.platform; 
/** * Get page Title */function Getpagetitle () {return document.title; 
  /** * Create a form * * @return/function Createsubmitform () {var frm = document.createelement ("form"); 
  Document.body.appendChild (frm); 
  Frm.method = "POST"; 
return frm; /** * Create an element for 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; /** * Constructs XMLHttpRequest Object * * @return/function createxmlhttprequest () {if (window).  
  ActiveXObject) {xmlHttp = new ActiveXObject (' microsoft.xmlhttp '); else if (window.  
  XMLHttpRequest) {xmlHttp = new XMLHttpRequest (); The/** * URL specifies the jump page, and data is the one to post. Func similar to function pointer * * @param URL * @param data * @param func * @return/functions ajaxpost (URL, data, func) {V 
  Ar 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 (http Request.status = = = {if (func) {//Here you can call the desired function 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=" + vlstatre FURL + "&url=" + Vlstaturl + "&screenx=" + Vlstatscreenx + "&screeny=" + Vlstatscreeny + "&os=" + V Lstatos + "&brower=" + vlstatbrower + "&browerlang=" + vlstatbrowerlanguage + "&title=" + vlstatPageTit 
  Le + "&ch=" + Vlstatch + "&ch1=" + vlstatCH1 + "&ch2=" + vlstatCH2 + "&ch3=" + vlstatCH3; 
  var Urlgo = vlstataction + "?" + P; 
  Createxmlhttprequest (); 
  Xmlhttp.open (' Get ', Urlgo); 
Xmlhttp.send (NULL); }

Related Article

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.