2009年5月10日 星期日

Blogger 顯示訪客上次瀏覽時間

添加HTML/JavaScript的Element,然後將下面的代碼直接添加進去即可:


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


實際上是理用了訪客的cookie記錄,所以當瀏覽器相關cookie記錄被清除之後,再次登陸網站時只會顯示為你第一次訪問

沒有留言:

張貼留言

Random Post

  • 豪華打磚塊 (s60v5)
    23.06.2009 - 0 Comments
  • 30樣你不太知道的東西
    01.06.2009 - 0 Comments
  • (Flash Game) Pillars
    19.07.2009 - 0 Comments
  • Windows 7 將於 2009 年假期前整裝待發
    14.05.2009 - 0 Comments
    http://arstechnica.com/microsoft ... by-holiday-2009.arsWindows 7 and Server 2008 R2 will be ready by holiday…
  • (Flash Game) 俄羅斯方塊
    13.05.2009 - 0 Comments
    Game Heat Flash Game Arcade