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