简单的JSt统计静态网站访问次数

Posted cat糯米团

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了简单的JSt统计静态网站访问次数相关的知识,希望对你有一定的参考价值。

最简单的静态页面刷新

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

效果图:

 

 

以上是关于简单的JSt统计静态网站访问次数的主要内容,如果未能解决你的问题,请参考以下文章

统计当前网页被访问次数的Jquery代码:

JavaScript实现网站访问次数统计代码

在HTML静态网页中记录图片被点击的次数统计代码?

关于网站页面访问量统计的问题

百度统计,统计页面加载时间,统计页面访问次数

JSP简单实现统计网页访问次数