Auto Greeting Script

Add a personal touch to your website. This script checks the user's current hour and displays a context-aware welcome message automatically.

Loading...

Based on your local time.

Copy the Script

<script>
var today = new Date();
var hour = today.getHours();
var greeting;

if (hour < 12) {
    greeting = "Good Morning!";
} else if (hour < 18) {
    greeting = "Good Afternoon!";
} else {
    greeting = "Good Evening!";
}

document.write("<h3>" + greeting + "</h3>");
</script>

Frequently Asked Questions

No. This script uses the client's system time (`new Date()`). If the user's computer clock is wrong, the greeting will be wrong.

Yes. You can add more `else if` statements to handle specific times, like 'Good Night' after 10 PM or 'Good Lunch' around noon.

Absolutely. You can change the text strings to anything you want, or even use this logic to change background images based on the time of day.