Results 1 to 1 of 1

Thread: Display time of last visit

  1. #1
    Senior Member ghaza's Avatar
    Join Date
    Oct 2013
    Location
    Multan, Pakistan
    Posts
    354

    Display time of last visit

    This script records the date+time of your visitor's last visit and displays it upon their return. If this is their first visit to your site, a greeting message is shown instead. You can customize the messages to display in each case.

    Simply insert the below script where you wish to display the Last Visit message:

    HTML Code:
    <script type = "text/javascript">
    
    
    
    var days = 730; // days until cookie expires = 2 years.
    var lastvisit=new Object();
    var firstvisitmsg="This is your first visit to this page. Welcome!"; 
    lastvisit.subsequentvisitmsg="Welcome back visitor! Your last visit was on <b>[displaydate]</b>";
    
    lastvisit.getCookie=function(Name){ 
    var re=new RegExp(Name+"=[^;]+", "i"); 
    if (document.cookie.match(re)) 
    return document.cookie.match(re)[0].split("=")[1];
    return''; 
    }
    
    lastvisit.setCookie=function(name, value, days){ 
    var expireDate = new Date();
    
    var expstring=expireDate.setDate(expireDate.getDate()+parseInt(days));
    document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/";
    }
    
    lastvisit.showmessage = function() {
    var wh = new Date();
    if (lastvisit.getCookie("visitc") == "") { 
    lastvisit.setCookie("visitc", wh, days); 
    document.write(firstvisitmsg);
    }
    
    else {
    var lv = lastvisit.getCookie("visitc");
    var lvp = Date.parse(lv);
    var now = new Date();
    now.setTime(lvp);
    var day = new Array("Sun", "Mon", "Tues", "Wed", "Thur", "Fri", "Sat");
    var month = new Array ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    var dd = now.getDate();
    var dy = now.getDay();
    dy = day[dy];
    var mn = now.getMonth();
    mn = month[mn];
    yy = now.getFullYear();
    var hh = now.getHours();
    var ampm = "AM";
    if (hh >= 12) {ampm = "PM"}
    if (hh >12){hh = hh - 12};
    if (hh == 0) {hh = 12}
    if (hh < 10) {hh = "0" + hh};
    var mins = now.getMinutes();
    if (mins < 10) {mins = "0"+ mins}
    var secs = now.getSeconds();
    if (secs < 10) {secs = "0" + secs}
    var dispDate = dy + ", " + mn + " " + dd + ", " + yy + " " + hh + ":" + mins + ":" + secs + " " + ampm
    document.write(lastvisit.subsequentvisitmsg.replace("\[displaydate\]", dispDate))
    }
    
    lastvisit.setCookie("visitc", wh, days);
    
    }
    
    lastvisit.showmessage();
    
    </script>
    Demo is available in the attachment..
    Attached Files Attached Files

Similar Threads

  1. Anyone know JS coding to display floating buttons?
    By Ayesh in forum Javascript and js libraries
    Replies: 0
    Last Post: 10-27-2013, 06:35 AM
  2. Javascript that display a random image
    By M.A.A in forum Javascript and js libraries
    Replies: 0
    Last Post: 10-03-2013, 04:23 PM
  3. Google Display Network Ad Planner
    By Masterr Mind in forum Google
    Replies: 0
    Last Post: 08-31-2013, 05:17 PM
  4. How many of you visit these places in delhi?
    By avisindia in forum Random Talk
    Replies: 0
    Last Post: 01-11-2012, 08:25 AM
  5. How to display ads just under after the lists of the threads
    By Jennifer in forum Forums Administration
    Replies: 3
    Last Post: 07-23-2010, 04:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •