Click to See Complete Forum and Search --> : Script needed please


michael
03-13-2003, 01:40 PM
Hi.
On my homepage I have a Java Script that displays a different message to the viewer depending on what the hour is. Very easy (seeing as I got it from a book).

What I am looking for now is a similar script, but one that displays a different home page depending on what the date is.

I would like to have my normal home page shown for most of the year, but have a more festive homepage displayed during the Christmas period or a more 'romantic' homepage shown on Valentines Day, etc....

I have looked everywhere for such a script but I can't find one.

If anyone knows of such a script could they please post a link to it on here, or if you already have a similar script yourself, please could you share it with me.

Thank you.
My website www.gwytherwebdesign.co.uk

gil davis
03-13-2003, 01:55 PM
Hopefully this is fairly self-explanitory:<script>
var urls = new Array();
for (var i=0; i<=11; i++) urls[i] = new Array();
// urls[month (0-11)][day (1-?)] = url
urls[0][1] = "newyear.htm";
urls[4][26] = "memorial.htm";
urls[6][4] = "independence.htm";
var now = new Date();
var mo = now.getMonth();
var dy = now.getDate();
if (urls[mo][dy]) {
window.location.href = urls[mo][dy];
}
</script>

requestcode
03-13-2003, 02:13 PM
If you wanted to display a page between two dates you could use this in the HEAD section of your document:
<SCRIPT LANGUAGE="JavaScript">
comparedate1=20030302
comparedate2=20030314
mydate=new Date()
curyear=mydate.getFullYear()
curmonth=mydate.getMonth()+1
if(curmonth<10)
{curmonth="0"+curmonth}
curday=mydate.getDate()
if(curday<10)
{curday="0"+curday}
curdate=curyear+""+curmonth+""+curday
if(curdate>comparedate1&&curdate<comparedate2)
{location.href="page1.html"}

</SCRIPT>