Forum Moderators: open
I want to show only on certain days of the year different images e.g. 4 of July should be a image with an US Flag there, on the 5. appears the "standard" image until maybe halloween - of course a halloween picture, until christmas standard again but on the 25. of Dec the xmas image .... and so on.
I don't want to make the changes always manual, I want to create and upload all the images and put the JavaScript in and thats it....am I dreaming or possible?
Any help is very appreciated, thanks, Andy
DRDOC
function changePicture() {
now = new Date();
month = now.getMonth() + 1;
day = now.getDate();
if(month == 7 && day == 4) {
document.write('<img src="images/jul4.jpg" alt="July 4" />');
}
else if(month == 10 && day == 31) {
document.write('<img src="images/oct31.jpg" alt="October 31" />');
}
else if(month == 12 && day == 25) {
document.write('<img src="images/dec25.jpg" alt="December 25" />');
}
else {
document.write('<img src="images/standard.jpg" alt="" />');
}
}
I suggest something like this in your <div> or <table>...
<script type="text/javascript">
//<![CDATA[
changePicture();
//]]>
</script>
M
You should use <![CDATA[ ]]> if you are using any special characters, such as [, ], >, <, and &, in your script.
However, if you put the script in an external js file you don't have to.
[w3.org...]
[xml.com...]
[webmasterworld.com...]
When JavaScript was first introduced, most browsers didn't recognize the <script> tag, so they ignored the tag and happily displayed the JavaScript code, blissfully unaware of the fact that this was not intended. Hence the need for the comments in the days when Netscape 2 ruled supreme.
Later browsers that didn't support JavaScript (I believe that includes WebTV, is that right?) did recognize the <script> tag. But to them, it meant (and still means) "ignore this, it's not for you".
On the basis that most browsers that didn't recognize <script> have probably gone out of circulation, you can probably safely omit the HTML comments.
Incidentally, one early version of the Lynx browser had real problems, because not only did it not recognize the <script> tag, but it also ended the HTML comment at the first > it came to. This meant that this code:
<script>
<!--
if(i>9) document.write('i is greater than 9');
// -->
</script>
generated the following display:
9) document.write('i is greater than 9');
Cross-browser compatibility was a major challenge even back then.