Stupid Web Tricks: Greet your Web visitors with a customized greeting

Teach your Web site good manners. Find out how to greet visitors with a greeting that's customized to the time of day.

Click here for our complete list of Stupid Web Tricks.

Once your site has demonstrated that it's smart enough to tell time, it's only polite to greet your visitors according to the time of day, such as "Good morning," or "Good afternoon." This will not only reflect your proper breeding, it will also enhance the personality of your site.

Note: Be aware that this trick uses JavaScript containing the document.write() method, which can create problems on pages with nested tables (such as this one).

Paste the code below into the <BODY> section of the page you want the greeting to appear on:

<SCRIPT language="javascript">

<!— hide javascript

document.write("<STRONG><FONT size=+2>");
day = new Date();
hr = day.getHours();
if ((hr >= 1) && (hr <=5)) {
   t = "Shouldn't you be in bed right now?";}
if ((hr >= 6) && (hr <=11)) {
   t = "Good morning!";}
if ((hr >= 12) && (hr <=16)) {
   t = "Good afternoon!";}
if ((hr >= 17) && (hr <=21)) {
   t = "Good evening!";}
if ((hr == 22) || (hr ==23)) {
   t = "Almost time for bed...";}
if (hr==0) {
   t = "It's past midnight...time to call it a night";}

// done hiding —>


Now your visitors will receive a customized greeting.

Editor's Picks

Free Newsletters, In your Inbox