Forum Moderators: open
I'm not much of a javascript guy, but I can occasionally edit other code to do what I want. However, I'm stumped on this one.
I'm trying to find code that will load a page based on the date (time of year). In other words, in summer (say Jun 23-Sep 22), I want page1.htm to load, in fall (Sep 23-Nov 22) I want page2.htm to load, etc.
I can't find any code that refers to date ranges (without the year), but have seen some using time of day. Can that type of code be altered to fit these parameters? I'd prefer to have the page be a redirect, but if it's just as easy, I guess I can work it into the menu so the correct page loads right away instead of being redirected.
Anyone have any ideas? Thanks in advance!
Chris
EDIT: I found this code from someone that was trying to have images change based on the season:
if((month<=11)&&(day<21))
season='images/fall.jpg';
if((month<=8)&&(day<21))//before September 21
season = 'images/summer.jpg';
if ((month<=5)&&(day<21))//before June 21
season = 'images/spring.jpg';
if (((month<=2)&&(day<21))¦¦((month==11)&&(day>20)))//before Mar 21 or after December 20
season = 'images/winter.jpg';
How could that be incorporated into determining the season, and then redirecting/loading the proper HTML page based on the results of that function?
[edited by: SleepyW at 4:18 am (utc) on July 17, 2007]
for example this perl snippet would give you the day of the year(0-364)(365 in leap years).
my %day = (localtime)[7];
then you could redirect based upon day of year.
if ( $day && $day < 90 ){ print "Location: this-file.html\n\n"; }
elsif ( $day && $day > 89 && $day < 180){ print "Location: that-file.html\n\n"; }
and so on...
I tried to modify some code based on the above, but not sure what/how to tweak it to get it to actually work. I know parts of it are wrong, but left it alone since I don't know what to replace. This was originally set up to display an image on this page based on the season - not redirect/load an HTML page.
<html>
<head>
<script language="JavaScript" type="text/javascript">
function setSeason()
{
if(document.page)
{
var today = new Date();
var month = today.getMonth()+1;
var day = today.getDate();
var season ='page.htm';
if ((month<=11)&&(day<21))
season ='fall.htm';
if ((month<=8)&&(day<21)) //before September 21
season ='summer.htm';
if ((month<=5)&&(day<21)) //before June 21
season ='spring.htm';
if (((month<=2)&&(day<21))¦¦((month==11)&&(day>20))) //before Mar 21 or after December 20
season ='winter.htm';
document.page['season'].src = season;
}
}
</script>
</head>
<body onload="setSeason()">
</body>
</html>
[edited by: SleepyW at 6:29 am (utc) on July 17, 2007]
function setSeason(){
var today = new Date();
var month = today.getMonth()+1;
var day = today.getDate();
var season ='page.htm';
if (month<=11 && day<21)
season ='fall.htm';
if (month<=8 && day<21) //before September 21
season ='summer.htm';
if (month<=5 && day<21) //before June 21
season ='spring.htm';
if ((month<=2 && day<21)¦¦(month==11 && day>20)) //before Mar 21 or after December 20
season ='winter.htm';
window.location.href = season;
}
this page will give you some stuff on using dates...
[quirksmode.org...]