怎樣在網站中實現統計訪問量的功能

來源:互聯網
上載者:User

標籤:substr   http   efi   asc   false   start   alt   ref   new   

有很多網站都會加一個訪問量統計的功能,其實代碼很簡單,全都是js寫的,而且代碼也不多

這個功能解釋一下就是,每訪問一次,網頁上面寫的訪問量就會增加一個,依次類推,下面就與大家分享一下實現這個功能的一段代碼

<script language=JavaScript><!--var caution = falsefunction 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 = curCookieelseif (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 nullvar cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)if (cookieEndIndex == -1)cookieEndIndex = document.cookie.lengthreturn 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 = 1elsevisits = parseInt(visits) + 1setCookie("counter", visits, now)document.write("您是第" + visits + "位訪問本專題的!")// --></script>

只需要這一段代碼就可以了,把它放在你想要放的位置,網站裡就會有這個功能了,看一下實現的

從我放上這個功能後,一共訪問了3次,所以上面顯示到了第3位,感興趣的也來試一下吧,喜歡的可以自己保留

怎樣在網站中實現統計訪問量的功能

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.