How to Display a Time-based Greeting message to Website visitors.

Wapdev Admin
Please wait 0 seconds...
Scroll Down and click on Go to Link for destination
Congrats! Link is Generated

Introduction

Websites have been known to greet visitors with a message that says Good morning, Good Afternoon, or Good Evening, depending on when they visit.

Time based greeting message html js


What is a Time-based Greeting Message?

Time-based Greeting is a function that can set a greeting message for the website visitors. Visitors will see the greeting message when they visit the website.

These are, in fact, simply client scripts that read the time on the active visitor's machine. In this article, I'll show you how to send a message to your website visitors. This post and the examples are intended for those who are new to the field.

How to Display a Time-based Greeting Message to Website Visitors?

This code will display a time-based greeting message to website visitors.


<label id="lblGreetings"></label>
<script>
    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 our Website';
</script>

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.