昆明噬撼电子有限公司

行業(yè)分享 2019-03-19 網(wǎng)頁(yè) 代碼

js網(wǎng)頁(yè)計(jì)數(shù)器實(shí)現(xiàn)代碼

今天客戶網(wǎng)站上要加一個(gè)網(wǎng)頁(yè)訪問(wèn)計(jì)數(shù)器的功能,下面是計(jì)數(shù)器的代碼

<script language="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>

下一篇 網(wǎng)站ICP備案一般需要多長(zhǎng)時(shí)間?

最新案例 查看更多

查看 
通州区| 海淀区| 石柱| 宁海县| 柞水县| 波密县| 进贤县| 闸北区| 塘沽区| 梨树县| 永年县| 本溪| 武冈市| 宜都市| 克拉玛依市| 浪卡子县| 青州市| 林口县| 星子县| 壤塘县| 乡宁县| 徐州市| 兴山县| 西盟| 晋城| 嘉禾县| 崇文区| 靖宇县| 高清| 定西市| 恭城| 永福县| 石楼县| 卓资县| 栾城县| 克什克腾旗| 富平县| 富阳市| 什邡市| 邳州市| 宜宾县|