I need a little help with a web page. I need to be able to have the page automatically display one bunch of HTML if it is winter (lets say between Dec. 1 and March 1), another if it's spring (March 1 to June 1), another for summer (June 1 to Sep. 1), and another for fall (Sep. 1 to Dec. 1). I used to know some Javascript (like, five years ago), and I've been scouring the Intertubes trying to find out how to do this.
Anyone have any ideas?
I used something like this for changing a pic according to the season on one of my websites recently, maybe this will help you:
Code for <head>:
<script language="JavaScript" type="text/javascript">
<!--
function SeasonalImage () {
var season=new Array();
season[0]="images/image_winter.jpg";
season[1]="images/image_spring.jpg";
season[2]="images/image_summer.jpg";
season[3]="images/image_fall.jpg";
var Date=new Date();
var d=Date.getDate();
var m=Date.getMonth()+1;
var s;
if(m>0&&m<=3)s=0;
if(m==3&&d>19)s=1;
if(m>3&&m<=6)s=1;
if(m==6&&d>20)s=2;
if(m>6&&m<=9)s=2;
if(m==9&&d>21)s=3;
if(m>9&&m<=12)s=3;
if(m==12&&d>20)s=0;
document.getElementById("season").src= season[s] ;
}
//-->
</script>
Code for <body>:
<div><img id="season" src="images/image_season.jpg" width="x" height="y"></div>
"image_season.jpg" is merely a placeholder that will be changed to the pic that is chosen by the script, so you can use a blank pic or something. I don't know JavaScript very well, too, but I guess you can change other elements, such as a DIV container with HTML code, as well with this method.
That sounds very server intensive Andreas, especially if that code is being run every time a page is requested. Would it not be better to set up a cron that would change an included header file (or something similar) on the first day of every "season"?
Fred
Since when does JavaScript run on the server? I thought that was client-based? It even works on my local HD when I open the HTML file with my browser, depending on the system date that I set.
Andreas is right....Javascript, as is HTML, a client side scripting language, so there should be no load on the server, unless the script was calling a function of the server software, but in this case as it's taking the date from the client machine, there's no load. A CRON is better suited for automatic processes that happen on a daily basis rather than quarterly :thumbsup:
And indeed you can change other elements using (nearly) that method, I made a simple picture gallery thing that I was going to make into a SMF mod but it didnt work and I lost the code
Joe