Saturday, November 6, 2010

记录上次访客登陆的时间及日期

这个可以记录访客上一次登录你部落格的日期与时间


步骤一:
Design > Add a Gadget (你要摆放的位子) > Html/Java Script


步骤二:
copy以下的code放入格子里就好了





    <script type="text/javascript">

    var lastvisit=new Object()
    lastvisit.firstvisitmsg="这是你第一次光临本站" //Change first visit message here
    lastvisit.subsequentvisitmsg="欢迎回来,你上一次到来是在 <b>[displaydate]</b>" //Change subsequent visit message here

    lastvisit.getCookie=function(Name){ //get cookie value
    var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
    if (document.cookie.match(re)) //if cookie found
    return document.cookie.match(re)[0].split("=")[1] //return its value
    return ""
    }

    lastvisit.setCookie=function(name, value, days){ //set cookei value
    var expireDate = new Date()
    //set "expstring" to either future or past date, to set or delete cookie, respectively
    var expstring=expireDate.setDate(expireDate.getDate()+parseInt(days))
    document.cookie = name+"="+value+" expires="+expireDate.toGMTString()+" path=/"
    }

    lastvisit.showmessage=function(){
    if (lastvisit.getCookie("visitcounter")==""){ //if first visit
    lastvisit.setCookie("visitcounter", 2, 730) //set "visitcounter" to 2 and for 730 days (2 years)
    document.write(lastvisit.firstvisitmsg)
    }
    else
    document.write(lastvisit.subsequentvisitmsg.replace("\[displaydate\]", new Date().toLocaleString()))
    }

    lastvisit.showmessage()

    </script>


完成!^^

No comments:

Post a Comment