Welcome to WebmasterWorld Guest from 54.145.39.186

Forum Moderators: open

Message Too Old, No Replies

Script to show a different image based on the month?

Such a Javascript would always make my site look up-to-date!

     

1Lit

3:01 pm on May 20, 2002 (gmt 0)

10+ Year Member



I already have a javascript to show different text based on the month, but I was wondering if anybody could refer me to a script which showed a different image for each month?

I recall seeing one a couple of years back where the script displayed a different graphic based on the month e.g. imagejanuary.gif imagefebruary.gif

Thank you :)

DrDoc

6:28 pm on May 20, 2002 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



<script language="javascript" type="text/javascript">
var months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
var thetime = new Date();
var themonth = thetime.getMonth();
document.write('<img src="image' + months[themonth] + '.gif" alt="Image of the month: ' + months[themonth] + '" />');
</script>

use image names like 'imageMay' and it will work just fine ;)

ergophobe

8:59 pm on May 20, 2002 (gmt 0)

WebmasterWorld Administrator ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



I'm probably not your typical browser, but to me such things just make a site look like it has Javascript (or PHP, ASP, whatever) that wastes bandwidth, especially since it is often obvious that the real content is hopelessly out of date. I think

"Page last updated: [date of last serious, major update]"

is useful, but

"Today's date is: [today's date]"

or worst of all

"Page last updated: [today's date or date last typo was fixed]"

are useless at best and will drive users away at worst since your credibility will be compromised. I hope that doesn't sound too negative. You know what they say about opinions....

Tom

1Lit

11:30 pm on May 20, 2002 (gmt 0)

10+ Year Member



Thank you VERY much DrDoc. I appreciate your help.

'ergophobe', I see your point. I work 12 hours a day/7 days a week to keep my sites up-to-date. However, I am trying to automate certain things so that I'll have the chance to leave me some time to occasionally take a few steps away from my PC :)

If I use such a script alongside similar text links, I could promote seasonal offers on my sites without having to make the changes manually? e.g. for my movie site: February = Romantic movies; October = Halloween movies; December = Christmas promotion.

Don't you think that is a good idea to automate such advertising and save myself time?

DrDoc

12:46 am on May 21, 2002 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



You're most welcome 1Lit! :)

I agree, it's good idea to let a script take care of 'updates' like that. I used to have a 'joke of the day' on one of my Web sites .. People loved it, even though they knew that it was automated.

But, ergophobe, I see your point. It is totally useless (will even have a negative impact on the visitor) to use JavaScript to 'fake' updates.

To have dynamic content, depending on the day or month, can be useful, if it has a purpose and if you used your brain when you thought of the purpose. ;)

1Lit

1:35 am on May 21, 2002 (gmt 0)

10+ Year Member



I've managed to do some quite nifty things with your script DrDoc, so thank you once again.

Just one other thing I wanted to ask: is there any way of making an ammendment to your script so that I can send the surfer to a different URL depending on the month? I've decided I'd like to send my visitors to a weight-loss site in January, flower-selling site in February, my Christmas store in December etc. :)

Thanks!

ergophobe

3:09 am on May 21, 2002 (gmt 0)

WebmasterWorld Administrator ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month




Don't you think that is a good idea to automate such advertising and save myself time?

Most definitely. That's why I was worried about sounding too negative, but I think you both took my point in the sense that it was intended. Dynamic content that is fed based on certain conditions is wonderful and worth the effort. I have just seen so many sites where the designer uses Javascript to *fake* freshness. It can be like the "NEW!!" label that identifies something from three years ago.

Dynamic methods of *creating* real fresh pages that give the user something appropriate is great, especially if you sell things that are themed (Valentine's day stuff in your case). Joke of the day can be great too.

Cheers,

Tom

DrDoc

3:55 pm on May 21, 2002 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



1Lit,

Just use the

document.write()
function and customize it for your needs.

Example:

document.write('<a href="' + months[themonth] + '.html">Link text goes here</a>');

And you know what? You can re-use the

months[themonth]
variable as often as you want. If you want several 'customized' links and images and what not .. just make sure that the first script I gave you is somewhere near the top of your page, preferrably in the HEAD section. Then, whenever you want to use it, just add another script that only contains the
document.write()
statment. Your browser will remember the value of the
months[themonth]
variable ;)

For redirection, just use this syntax:

location.href = months[themonth] + ".html";
 

Featured Threads

Hot Threads This Week

Hot Threads This Month