JavaScript to achieve site access number of statistics code _JAVASCRIPT skills

Source: Internet
Author: User
Tags setcookie

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.

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.