[JS12] 统计访问次数

 

 1 <html>
 2 <head>
 3     <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
 4         <title>New Page 5</title>
 5     <meta name="GENERATOR" content="Microsoft FrontPage 3.0">
 6     <script language="JavaScript">
 7         <!--
 8         var caution = false
 9         function setCookie(name, value, expires, path, domain, secure) {
10             var curCookie = name + "=" + escape(value) +
11             ((expires) ? "; expires=" + expires.toGMTString() : "") +
12             ((path) ? "; path=" + path : "") +
13             ((domain) ? "; domain=" + domain : "") +
14             ((secure) ? "; secure" : "")
15             if (!caution || (name + "=" + escape(value)).length <= 4000)
16                 document.cookie = curCookie
17             else if (confirm("Cookie exceeds 4KB and will be cut!"))
18                 document.cookie = curCookie
19         }
20         function getCookie(name) {
21             var prefix = name + "="
22             var cookieStartIndex = document.cookie.indexOf(prefix)
23             if (cookieStartIndex == -1)
24                 return null
25             var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
26             if (cookieEndIndex == -1)
27                 cookieEndIndex = document.cookie.length
28             return unescape(document.cookie.substring(cookieStartIndex + prefix.length,
29             cookieEndIndex))
30         }
31         function deleteCookie(name, path, domain) {
32             if (getCookie(name)) {
33                 document.cookie = name + "=" +
34                 ((path) ? "; path=" + path : "") +
35                 ((domain) ? "; domain=" + domain : "") +
36                 "; expires=Thu, 01-Jan-70 00:00:01 GMT"
37             }
38         }
39         function fixDate(date) {
40             var base = new Date(0)
41             var skew = base.getTime()
42             if (skew > 0)
43             date.setTime(date.getTime() - skew)
44         }
45         var now = new Date()
46         fixDate(now)
47         now.setTime(now.getTime() + 730 * 24 * 60 * 60 * 1000)
48         var visits = getCookie("counter")
49         if (!visits)
50             visits = 1
51         else
52             visits = parseInt(visits) + 1
53         setCookie("counter", visits, now)
54         document.write("<font size=6 color=red>欢迎您,您是第:" + visits + " 个访问该站点的访客")
55         // -->
56     </script>
57 </head>
58 <body>
59     <p align="right"> </p>
60 </body>
61 </html>

 

posted @ 2014-05-13 23:58  beautifulzzzz  阅读(1385)  评论(0编辑  收藏  举报