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.
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>