美文网首页
JavaScript网页被访问次数方法

JavaScript网页被访问次数方法

作者: 温柔蟹子小龙女 | 来源:发表于2017-12-18 15:37 被阅读0次

    varcaution=false

    functionsetCookie(name,value,expires,path,domain,secure)

    {

    varcurCookie=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

    }

    elseif(confirm("Cookie exceeds 4KB and will be cut!"))

    {

    document.cookie = curCookie

    }

    }

    functiongetCookie(name)

    {

    varprefix = name +"="

    varcookieStartIndex = document.cookie.indexOf(prefix)

    if(cookieStartIndex == -1)

    {

    returnnull

    }

    varcookieEndIndex=document.cookie.indexOf(";",cookieStartIndex+prefix.length)

    if(cookieEndIndex == -1)

    {

    cookieEndIndex = document.cookie.length

    }

    returnunescape(document.cookie.substring(cookieStartIndex+prefix.length,cookieEndIndex))

    }

    functiondeleteCookie(name, path, domain)

    {

    if(getCookie(name))

    {

    document.cookie = name +"="+

    ((path) ?"; path="+ path :"") +

    ((domain) ?"; domain="+ domain :"") +

    "; expires=Thu, 01-Jan-70 00:00:01 GMT"

    }

    }

    functionfixDate(date)

    {

    varbase=newDate(0)

    varskew=base.getTime()

    if(skew>0)

    {

    date.setTime(date.getTime()-skew)

    }

    }

    varnow=newDate()

    fixDate(now)

    now.setTime(now.getTime()+365 * 24 * 60 * 60 * 1000)

    varvisits = getCookie("counter")

    if(!visits)

    {

    visits=1;

    }

    else

    {

    visits=parseInt(visits)+1;

    }

    setCookie("counter", visits, now)

    //document.write("您是到访的第" + visits + "位用户!")

    console.log("您是到访的第"+ visits +"位用户!");

    相关文章

      网友评论

          本文标题:JavaScript网页被访问次数方法

          本文链接:https://www.haomeiwen.com/subject/bkjmwxtx.html