As a website administrator or webmaster, all want to know how many people visited the site, this time need to have a statistical function to meet the needs, of course, the function is relatively simple, if you want a strong statistical effect, it is best to use now more sophisticated statistical tools, such as webmaster statistics or Tencent statistics and so on.
Code One:
The code is as follows:
<script type= "Text/javascript" > var caution=false function Setcookie (name,value,expires,path,domain,secure) { var curcookie=name+ "=" +escape (value) + ((expires)? "; Expires= "+expires.togmtstring ():" ") + ((path)?"; Path= "+ Path:" "+ (domain)?"; domain= "+ domain:" ") + ((secure)?"; Secure ":" ") if (!caution| | (name + "=" + Escape (value)). Length <= 4000) {document.cookie = Curcookie} else if (Confirm ("Cookie exceeds 4KB an
D would be cut! "))
{document.cookie = Curcookie}} function GetCookie (name) {var prefix = name + "=" var Cookiestartindex = document.cookie.indexOf (prefix) if (cookiest Artindex = = 1) {return null} var cookieendindex=document.cookie.indexof (";", Cookiestartindex+prefix.length) if
(Cookieendindex =-1) {cookieendindex = document.cookie.length} return unescape (Document.cookie.substring (cookiestartindex+prefix.length , Cookieendindex)} function Deletecookie (name, path, domain) {if (GetCookie (name)) {Document.cookie = name + "=" + (path)? "; Path= "+ Path:" "+ (domain)?"; domain= "+ domain:" "+"; Expires=thu, 01-jan-70 00:00:01 GMT "}} function Fixdate (date) {var base=new date (0) var skew=base.gettime () if (Ske w>0) {date.settime (Date.gettime ()-skew)}} var now=new date () fixdate (now) Now.settime (Now.gettime () +365 * 24
* * 1000) var visits = GetCookie ("Counter") if (!visits) {Visits=1;}
else {Visits=parseint (visits) +1;} Setcookie ("Counter", visits, now) document.write ("You are visiting the first" + Visits + "User! ") </script>
Code two:
The code is as follows:
<script type= "Text/javascript" > var caution=false function Setcookie (name,value,expires,path,domain,secure) { var curcookie=name+ "=" +escape (value) + ((expires)? "; Expires= "+expires.togmtstring ():" ") + ((path)?"; Path= "+ Path:" "+ (domain)?"; domain= "+ domain:" ") + ((secure)?"; Secure ":" ") if (!caution| | (name + "=" + Escape (value)). Length <= 4000) {document.cookie = Curcookie} else if (Confirm ("Cookie exceeds 4KB an
D would be cut! "))
{document.cookie = Curcookie}} function GetCookie (name) {var prefix = name + "=" var Cookiestartindex = document.cookie.indexOf (prefix) if (cookiest Artindex = = 1) {return null} var cookieendindex=document.cookie.indexof (";", Cookiestartindex+prefix.length) if
(Cookieendindex =-1) {cookieendindex = document.cookie.length} return unescape (Document.cookie.substring (cookiestartindex+prefix.length , Cookieendindex)} function Deletecookie (name, path, domain) {if (GetCookie (name)) {Document.cookie = name + "=" + (path)? "; Path= "+ Path:" "+ (domain)?"; domain= "+ domain:" "+"; Expires=thu, 01-jan-70 00:00:01 GMT "}} function Fixdate (date) {var base=new date (0) var skew=base.gettime () if (Ske w>0) {date.settime (Date.gettime ()-skew)}} var now=new date () fixdate (now) Now.settime (Now.gettime () +365 * 24
* * 1000) var visits = GetCookie ("Counter") if (!visits) {Visits=1;}
else {Visits=parseint (visits) +1;} Setcookie ("Counter", visits, now) document.write ("You are visiting the first" + Visits + "User! ") </script>
The above two ways to achieve JavaScript statistics web site Traffic Code, I hope to help.