A simple Website access JS counter refresh once + 1 Access

Source: Internet
Author: User

Copy codeThe Code is as follows: <script language = "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 and will be cut! "))
Document. cookie = curCookie
}
Function getCookie (name ){
Var prefix = name + "="
Var cookieStartIndex = document. cookie. indexOf (prefix)
If (cookieStartIndex =-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 (skew> 0)
Date. setTime (date. getTime ()-skew)
}
Var now = new Date ()
FixDate (now)
Now. setTime (now. getTime () + 365*24*60*60*1000)
Var visits = getCookie ("counter ")
If (! Visits)
Visits = 1
Else
Visits = parseInt (visits) + 1
SetCookie ("counter", visits, now)
Document. write ("you are the first user to visit" + visits +! ")
// -->
</Script>

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.