Display a Greeting message to your visitors based on Time

We have seen websites greeting their visitors with a message that says Good morning, good afternoon or good evening, depending upon the time they visit the website. In fact, these are simple client scripts, which read the active visitors computer’s time. Here, in this article, I’ll show you how to greet your website visitors with a message. This article and the examples are for beginners.


Copy & Paste the Code

  <label id="lblGreetings"></label>

    var myDate = new Date();
    var hrs = myDate.getHours();

    var greet;

    if (hrs <= 12 && hrs >= 4)
        greet = 'Good Morning';
    else if (hrs >= 12 && hrs <= 17)
        greet = 'Good Afternoon';
    else if (hrs >= 17 && hrs <= 22)
        greet = 'Good Evening';
    else if (hrs >= 22 && hrs < 4)
        greet = 'Good Night';

 document.getElementById('lblGreetings').innerHTML =
        '<strong>' + greet + '</strong> and welcome to WapMash.xyz';


Leave a Reply