JavaScript實(shí)現(xiàn)網(wǎng)站訪問次數(shù)統(tǒng)計代碼
作為一個網(wǎng)站的管理員或者說站長,都希望知道到底有多少人訪問了網(wǎng)站,這個時候就需要有一個統(tǒng)計功能來滿足需要,當(dāng)然功能比較單一和簡單,如果想要強(qiáng)大的統(tǒng)計效果,那最好還是使用現(xiàn)在比較成熟的統(tǒng)計工具,比如站長統(tǒng)計或者騰訊統(tǒng)計等等。
代碼一:
代碼如下:
<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 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("您是到訪的第" + visits + "位用戶!") </script>
代碼二:
代碼如下:
<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 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("您是到訪的第" + visits + "位用戶!") </script>
以上通過兩種方式實(shí)現(xiàn)JavaScript統(tǒng)計網(wǎng)站訪問量的代碼,希望對大家有所幫助。
- JS 精確統(tǒng)計網(wǎng)站訪問量的實(shí)例代碼
- 一個簡單的網(wǎng)站訪問JS計數(shù)器 刷新1次加1次訪問
- ASP.net中網(wǎng)站訪問量統(tǒng)計方法代碼
- 利用google提供的API(JavaScript接口)獲取網(wǎng)站訪問者IP地理位置的代碼詳解
- javascript實(shí)現(xiàn)的網(wǎng)站訪問量統(tǒng)計代碼
- Windows Server 2008 R2網(wǎng)站訪問PHP響應(yīng)慢的解決方法
- Javascript自定義函數(shù)判斷網(wǎng)站訪問類型是PC還是移動終端
- python實(shí)現(xiàn)用于測試網(wǎng)站訪問速率的方法
- php獲得網(wǎng)站訪問統(tǒng)計信息類Compete API用法實(shí)例
- Java web網(wǎng)站訪問量的統(tǒng)計
相關(guān)文章
基于JS實(shí)現(xiàn)點(diǎn)擊圖片在彈出層顯示大圖效果
Javascript是個好東西。Jquery是基于這個好東西的一個強(qiáng)大的庫。本文將利用JavaScript實(shí)現(xiàn)點(diǎn)擊圖片在彈出層顯示大圖功能,感興趣的可以了解一下2022-08-08神級程序員JavaScript300行代碼搞定漢字轉(zhuǎn)拼音
這篇文章主要介紹了神級程序員JavaScript300行代碼搞定漢字轉(zhuǎn)拼音,需要的朋友可以參考下2017-05-05使用微信內(nèi)嵌H5網(wǎng)頁解決JS倒計時失效問題
最近參考項(xiàng)目開發(fā),遇到這樣一個需求將H5商城頁面嵌套到公司微信公眾號里,在開發(fā)遇到一個棘手的問題,js倒計時失效問題,怎么回事呢?下面說下我使用微信內(nèi)嵌h5解決的這一問題,需要的朋友參考下吧2017-01-01模擬javascript中的sort排序(簡單實(shí)例)
下面小編就為大家?guī)硪黄Mjavascript中的sort排序(簡單實(shí)例)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-08-08js實(shí)現(xiàn)帶有介紹的Select列表菜單實(shí)例
這篇文章主要介紹了js實(shí)現(xiàn)帶有介紹的Select列表菜單,涉及javascript頁面元素的動態(tài)操作技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-08-08