From desktops to servers, find the right IT Support for your business.

Date Linked Messages Script

Having a small body of text display at specific times can be useful - here's the code to make it work

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var days = new Array();
var msgs = new Array();
days[1] = "January 22, 2002";
msgs[1] = "Hello! This page was released today.";
days[0] = "January 23, 2002";
msgs[0] = "This page was released yesterday, but you're only visiting today!";
days[2] = "January 24, 2002";
msgs[2] = "It's Friday tomorrow - nearly the end of the week!";
days[3] = "January 25, 2002";
msgs[3] = "It's Friday! Finish early, go to pub!";
days[4] = "January 26, 2002";
msgs[4] = "It's Saturday today... hope you had a long lie in!";
days[5] = "January 27, 2002";
msgs[5] = "This was released on Tuesday - glad you got round to reading it!";
var months = new Array("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var today = new Date(); // today
var mon = months[today.getMonth() + 1]; // month
var day = today.getDate(); // day
var year = y2k(today.getYear()); // year
function dateMsg() {
for (i = 0; i < days.length; i++) {
tempdate = new Date(days[i]); tempmonth = months[tempdate.getMonth() + 1];
tempday = tempdate.getDate();
tempyear = y2k(tempdate.getYear());
if (year == tempyear && mon == tempmonth && day == tempday)
return( msgs[i]); // returns day message
}
return("Today is " + mon + " " + day + ", " + year + "."); // returns default
}
// Y2K Fix Function function
y2k(year) {
if (year < 2000) year = year + 1900;
return year; }
// End -->

Copy all of the above code and paste it into the <head> section of your page. Edit the dates and messages to suit yourself Once you've done that, copy the code below and place it into the <body> section of your page wherever you want the message to be displayed.

<script>
document.write(dateMsg());
</script>

That's pretty much all there is to it - quick and simple! Enjoy

David Dorn

Keep up to Date with PPC

RSS feed icon

Add to Google
Free Sitemap Generator