Dynamic welcome messages
 
02/10/2005 - 22:01 (Category: Javascript)

A nice idea for your web site: dynamic welcome messages according to particular circumstances (e.g.: different hours of the day).

This script is compatible with Explorer, Netscape 6, Mozilla, Safari, Opera.

You must put this script inside of <body> and </body> tags in your web page (where you want the message displayed).


<script language="Javascript" type="text/javascript">
<!--
oracorrente = new Date
if (oracorrente.getHours() < 5) {
document.write("What you do here in the middle of the night??")
}
else if (oracorrente.getHours() < 12) {
document.write("Good morning!!")
}
else if (oracorrente.getHours() < 17) {
document.write("Good afternoon!!")
}
else {
document.write("Good evening!!")
}

// -->
</script>



The oracorrente variable contains one instance of the Date object (the visitor's PC local time).
Now, by means of the getHours() method, you can get current time stored into the oracorrente variable (oracorrente.getHours()).

Then, by means of some conditional expressions (if/else if/else) you will get ad hoc messages.
Example: At 3 a.m. (notice that 3 is less than 5) the displayed message will be: What are you doing here in the middle of the night??.

You can also customize output messages as you like
Remember: by means of the document.write() method, you can write whole HTML pages (not only little messages).
Furthermore, you can replace the message text: What you do here in the middle of the night??: with HTML code.

Go back

DISCLAIMER:
Any named products on this website are copyright © and/or trademarks ® of their respective companies. INFORMATION ON THIS WEB SITE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. The material included in this site has been compiled from a variety of sources and the site may include technical inaccuracies or typographical errors. Information may be changed or updated without notice. While every effort is made to ensure the correctness of the information provided here, the author can accept no responsibility for damages caused directly or indirectly from the use of such information. The author will not be responsible for damage or loss of data. You are advised to backup data regularly! By entering this site you are agreeing to this and also to never suing the author.

 

Home  About  Mail us!  

Copyright © 1998-2006 Wowarea