Translate This Blog
Remember To Always Back Up Your Template Before Attempting Any Of The Tweaks On This Site

Greeting Message for All Times Of The Day

This is a JavaScript alert message that will greet your visitors with a different message for anytime of the day. This is actually the first JavaScript I have ever wrote so enjoy.

If the user has JavaScript blocked on their browser or their browser does not support it, then they may not see this message. When you entered this page you should of been greeted with a message, if not then you have JavaScript blocked or your browser does not support it.

1 Just add this script below anywhere you want the greeting message to appear. If you add it into a gadget then it will display on all pages in your blog.
<script type="text/javascript">
function morning(){alert("Good Morning!");}function afternoon(){alert("Good Afternoon!");}function night(){alert("Have a Good Night!");}</script>
<script type="text/javascript">var d = new Date();var time = d.getHours();if (time < 11){morning();}else if (time > 17){night();}else{afternoon();}
</script>
2. Replace the colored text with the message you want to display.

Orange message will display from 12am-12pm.
Red message  will display from 12pm-6pm
Light Blue message will display from 6pm-12am

3. Optional
If you noticed I colored 2 areas in the bottom of the script. You don't have to change these unless you want to. Basically these are used to change the time the messages will display. Right now the times above will be what time the messages display.

If you do want to change these then you will need to understand what they do. As we all know one day is built up of 24 hours. Well the numbers work from 1-24 with each number referring to the time between the number and the next.

1=1am-2am
2=2am-3am
3=3am-4am

The basic coding syntax for the time is pretty simply to understand.

if (time < 11) {morning 

This above means "If time is less then 11am greet with morning message" ( 11=11am-12pm)

else if (time > 17){night

This above means "If time is greater then 5pm greet with night message" (17=5pm-6pm)

Any unassigned time between those two will automatically greet with afternoon message.




3 comments:

Anonymous said...

Hello, where to add this? it is unclear. Hope you'll tell.

AiresOFwar said...

Add it into a HTML/JaaScript Gadget

AiresOFwar said...

If you only want it to display on the homepage then you can add some conditional tags within the template to hide it.

Post a Comment

Please don't post hyperlinked text within the comment box! It will not be published and you will be marked as spam.

Web Design Blogs PageRank