Posted By

michellebracken on 12/25/10


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

michellebracken


Show visitors the last time they visted


 / Published in: HTML
 

  1. <script type = "text/javascript">
  2.  
  3. /***********************************************
  4. * Display time of last visit script- by JavaScriptKit.com
  5. * This notice MUST stay intact for use
  6. * Visit JavaScript Kit at http://www.javascriptkit.com/ for this script and more
  7. ***********************************************/
  8.  
  9. var days = 730; // days until cookie expires = 2 years.
  10. var lastvisit=new Object();
  11. var firstvisitmsg="FIRST VISIT DISPLAY HERE";
  12. lastvisit.subsequentvisitmsg="VISIT DISPLAY HERE. YOUR LAST VIST WAS ON [displaydate]";
  13.  
  14. lastvisit.getCookie=function(Name){
  15. var re=new RegExp(Name+"=[^;]+", "i");
  16. if (document.cookie.match(re))
  17. return document.cookie.match(re)[0].split("=")[1];
  18. return'';
  19. }
  20.  
  21. lastvisit.setCookie=function(name, value, days){
  22. var expireDate = new Date();
  23.  
  24. var expstring=expireDate.setDate(expireDate.getDate()+parseInt(days));
  25. document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/";
  26. }
  27.  
  28. lastvisit.showmessage = function() {
  29. var wh = new Date();
  30. if (lastvisit.getCookie("visitc") == "") {
  31. lastvisit.setCookie("visitc", wh, days);
  32. document.write(firstvisitmsg);
  33. }
  34.  
  35. else {
  36. var lv = lastvisit.getCookie("visitc");
  37. var lvp = Date.parse(lv);
  38. var now = new Date();
  39. now.setTime(lvp);
  40. var day = new Array("Sun", "Mon", "Tues", "Wed", "Thur", "Fri", "Sat");
  41. var month = new Array ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
  42. var dd = now.getDate();
  43. var dy = now.getDay();
  44. dy = day[dy];
  45. var mn = now.getMonth();
  46. mn = month[mn];
  47. yy = now.getFullYear();
  48. var hh = now.getHours();
  49. var ampm = "AM";
  50. if (hh >= 12) {ampm = "PM"}
  51. if (hh >12){hh = hh - 12};
  52. if (hh == 0) {hh = 12}
  53. if (hh < 10) {hh = "0" + hh};
  54. var mins = now.getMinutes();
  55. if (mins < 10) {mins = "0"+ mins}
  56. var secs = now.getSeconds();
  57. if (secs < 10) {secs = "0" + secs}
  58. var dispDate = dy + ", " + mn + " " + dd + ", " + yy + " " + hh + ":" + mins + ":" + secs + " " + ampm
  59. document.write(lastvisit.subsequentvisitmsg.replace("[displaydate]", dispDate))
  60. }
  61.  
  62. lastvisit.setCookie("visitc", wh, days);
  63.  
  64. }
  65.  
  66. lastvisit.showmessage();
  67.  

Report this snippet  

You need to login to post a comment.