Saturday, February 23, 2013

Display the time and date of the last visit of your visitors

Display the time and date of the last visit of your visitors

Hello friends, today I came with a new widget that shows the Time and Date of the last visit of your visitors. This widget shows a message with the time and date of your visitor's last arrive. If the visitor visits first time it shows a welcome message. If the visitor revisits your site, it shows the time and date with a message. Let's see how to add this widget.

Step 1
Login to your blogger dashboard and go to Layout >> Add a Gadget >> HTML/JavaScript. Now copy below code and paste into text area of the HTML/JavaScript.

<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 My page. Welcome!";
lastvisit.subsequentvisitmsg="Welcome back Friend! Your last visit on my page <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>
<p><a href="http://www.myetricks.com/2013/02/display-time-and-date-of-last-visit-of-your-visitors.html"/><span style="font-size: 80%">Grab this</span></a></p>
  

Step 2
Now save your widget and view blog.
Is it Working or Not? Please leave your comments.

3 comments:

  1. Greetings! Very useful advice in this particular post!
    It is the little changes that make the largest changes.
    Thanks a lot for sharing!

    my weblog; flash casinos no deposit

    ReplyDelete
  2. Hi there, I wish for to subscribe for this webpage to
    get newest updates, thus where can i do it please assist.


    My webpage; safety harnesses and accessories Gauteng
    My webpage > fertilisers Gauteng

    ReplyDelete
    Replies
    1. There is a widget for the subscription at the top of the side bar.
      I solved error of it. you can now subscribe us.
      thanks!

      Delete