简单的JS统计静态网站访问次数
最简单的静态页面刷新
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>
效果图:
既然选择了远方,便只顾风雨兼程。