Display image based on upcoming holiday

Y

Yeah

I have a web site which changes the header logo based on the upcoming
holiday.

For example, from December 10th to 25th, XMAS.JPG is displayed. From October
20th to 31st, HALLWEEN.JPG is displayed. Etc. etc. If today's date is not
near a holiday, then the default LOGO.JPG is displayed.

A while back, I was looking for a JavaScript that does this automagically.
But each snippet I found traditionally displays the default logo for a
second, then switches to the holiday logo. I had one years ago that
*instantly* displays the correct logo (but I misplaced it).

Can anybody point me to a more efficient JavaScript solution? Any help is
appreciated. Thanks!
 
R

RobG

Yeah said:
I have a web site which changes the header logo based on the upcoming
holiday.

For example, from December 10th to 25th, XMAS.JPG is displayed. From October
20th to 31st, HALLWEEN.JPG is displayed. Etc. etc. If today's date is not
near a holiday, then the default LOGO.JPG is displayed.

A while back, I was looking for a JavaScript that does this automagically.
But each snippet I found traditionally displays the default logo for a
second, then switches to the holiday logo. I had one years ago that
*instantly* displays the correct logo (but I misplaced it).

Can anybody point me to a more efficient JavaScript solution? Any help is
appreciated. Thanks!

Do it on your server - create a copy of LOGO.JPG called BANNER.JPG (or
similar) then replace LOGO.JPG in your markup with BANNER.JPG.

Have a script run on your server each day (say at 5 minutes past
midnight) that copies the appropriate image to BANNER.JPG.

No client-side script and hopefully much more reliable. Users in
different time zones will see the changed banner at different local
times, but that doesn't seem important here.


A script based solution might be:


<img name="theBanner" src="LOGO.JPG">

<script type="text/javascript">

function changeBanner()
{
var nowDate = new Date();
var m = nowDate.getMonth()+1; // Months are zero-indexed - jan=0
var d = nowDate.getDate();
var bannerImg;

if (document.images && (bannerImg = document.images.theBanner)){

if (12 == m && (d>9 && d<26)){
bannerImg.src = 'XMAS.JPG';

} else if (10 == m && (d>19 && d<32)){
bannerImg.src = 'HALLWEEN.JPG';
}
}
}

</script>


But you are at the whim of client-side scripting and whether the
users' system has been set with an accurate date. You are probably
better off to put all your image names in lower case, but it's not
much of an issue.
 
Y

Yeah

Thanks for the prompt response! This seems like an excellent plan. Small
question: why is HALLWEEN.JPG an "else if" if the default non-holiday logo
is LOGO.JPG? It would appear to me that all holidays should be "if"s and the
default should be an "else if"...
 
R

RobG

Yeah said:
Thanks for the prompt response! This seems like an excellent plan. Small
question: why is HALLWEEN.JPG an "else if" if the default non-holiday logo
is LOGO.JPG? It would appear to me that all holidays should be "if"s and the
default should be an "else if"...

Please don't top-post. Trim quoted text and reply after the relevant
part.

If it's Christmas, there's no point in the 'if' going any further.
Using an else if is like putting a return in the first 'if' statement
to stop the second from being tested if the first is true - only one
condition can be true at a time.

There is no need for a default, since the default banner is loaded
anyway. Users without scripting will just see the default always.


[...]

Start loading the default banner.


[...]

If the date is within the 'show XMAS image' time frame...


replace the default with the XMAS image.


If we're not within the XMAS time frame, see if we're within the
Halloween time frame...


if so, replace the default image with the Halloween image.


If not within either time frame, don't do anything - leave the default
banner alone.


[...]
 
D

Dr John Stockton

JRS: In article <D8mtf.70439$sg5.44136@dukeread12>, dated Fri, 30 Dec
2005 20:37:29 local, seen in Yeah
I have a web site which changes the header logo based on the upcoming
holiday.

For example, from December 10th to 25th, XMAS.JPG is displayed. From October
20th to 31st, HALLWEEN.JPG is displayed. Etc. etc. If today's date is not
near a holiday, then the default LOGO.JPG is displayed.

Surely Halloween is not a holiday?

The Web is international; so, in order to avoid seeming stupid, you need
to use the client date rather than the server date or GMT.

Telling New Zealanders "Tonight is Halloween" at 2006-10-31 23:30 GMT,
while they're feeling it's nearly lunchtime on November 1st, is
ludicrous.

if the client has not got his date and time set correctly for his
locale, that's his problem; and it may indeed be well to indicate it.

Of course, if your message is "My (the author's) Halloween is not yet
over", then you need to use GMT, and to correct it to your personal
location (remembering, if you are alas an American, that Halloween 2006
will probably be your last to occur in early Winter time.
Can anybody point me to a more efficient JavaScript solution? Any help is
appreciated. Thanks!

If you are a programmer, you can find general and specific information,
but not necessarily a complete solution, at
<URL:http://www.merlyn.demon.co.uk/js-dates.htm>
<URL:http://www.merlyn.demon.co.uk/js-date6.htm>
 
J

John W. Kennedy

Yeah said:
I have a web site which changes the header logo based on the upcoming
holiday.

For example, from December 10th to 25th, XMAS.JPG is displayed. From October
20th to 31st, HALLWEEN.JPG is displayed. Etc. etc. If today's date is not
near a holiday, then the default LOGO.JPG is displayed.

A while back, I was looking for a JavaScript that does this automagically.
But each snippet I found traditionally displays the default logo for a
second, then switches to the holiday logo. I had one years ago that
*instantly* displays the correct logo (but I misplaced it).

Can anybody point me to a more efficient JavaScript solution? Any help is
appreciated. Thanks!

I solved it by making a one-pixel transparent PNG and making that the
default. (This assumes that all the logos are the same size, and that
size is given, either by HTML or CSS.)

--
John W. Kennedy
"But now is a new thing which is very old--
that the rich make themselves richer and not poorer,
which is the true Gospel, for the poor's sake."
-- Charles Williams. "Judgement at Chelmsford"
 
R

Randy Webb

Dr John Stockton said the following on 1/1/2006 9:16 AM:
JRS: In article <D8mtf.70439$sg5.44136@dukeread12>, dated Fri, 30 Dec
2005 20:37:29 local, seen in Yeah



Surely Halloween is not a holiday?

No more, and no less, than Christmas is. Your bias is painfully obvious.
The Web is international; so, in order to avoid seeming stupid, you need
to use the client date rather than the server date or GMT.

The OP said nothing about Server Time and was asking for a client
solution. That alone indicates using the client clock.
Telling New Zealanders "Tonight is Halloween" at 2006-10-31 23:30 GMT,
while they're feeling it's nearly lunchtime on November 1st, is
ludicrous.

So is telling Israeli's that "Tomorrow is Christmas" on December 24.
if the client has not got his date and time set correctly for his
locale, that's his problem; and it may indeed be well to indicate it.

The user does not always have access, nor inclination, to reset the
clock. Internet Cafe.
Of course, if your message is "My (the author's) Halloween is not yet
over", then you need to use GMT, and to correct it to your personal
location (remembering, if you are alas an American, that Halloween 2006
will probably be your last to occur in early Winter time.

That wasn't the question. It could have just as well been asked as an
"Upcoming Events" calendar and the solution is the same.
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated
Sun, 1 Jan 2006 13:02:07 local, seen in Randy
Webb said:
Dr John Stockton said the following on 1/1/2006 9:16 AM:

No more, and no less, than Christmas is. Your bias is painfully obvious.

Christmas is a holiday throughout the Western world; I don't know
anywhere that has Halloween as a holiday. The normal meaning of holiday
is a no-work day.

The OP said nothing about Server Time and was asking for a client
solution. That alone indicates using the client clock.

Agreed; but someone else favoured using Server Time or GMT.

So is telling Israeli's that "Tomorrow is Christmas" on December 24.

Again an errant apostrophe. Actually, it's quite useful. Jerusalem and
Christianity are strongly linked, and Christmas is certainly celebrated
there. Granted, it is probably not a national Bank Holiday.

The user does not always have access, nor inclination, to reset the
clock. Internet Cafe.

Then choose a better Cafe, or tell the manager.

That wasn't the question.

No : it's an auxiliary answer. Often an OP does not understand the
possible complexities well enough to pose a question for which all that
should be said is a direct answer.
 
L

Lee

Dr John Stockton said:
Christmas is a holiday throughout the Western world; I don't know
anywhere that has Halloween as a holiday. The normal meaning of holiday
is a no-work day.

That may be the normal meaning in British English, but not in American.

I very often go to work on holidays, and most of my days off of work
do not fall on holidays.
 
J

John W. Kennedy

Dr said:
Christmas is a holiday throughout the Western world; I don't know
anywhere that has Halloween as a holiday. The normal meaning of holiday
is a no-work day.

Would you cavil at so designating Guy Fawkes Night?

--
John W. Kennedy
"But now is a new thing which is very old--
that the rich make themselves richer and not poorer,
which is the true Gospel, for the poor's sake."
-- Charles Williams. "Judgement at Chelmsford"
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Mon, 2 Jan 2006
17:36:34 local, seen in John W. Kennedy
Would you cavil at so designating Guy Fawkes Night?

It's not even a day, let alone a holiday. It has none of the essential
properties of a holiday.

The Anniversary of the Battle of the Boyne is, however, a local holiday.

BTW, unless otherwise qualified, the term "holiday" means a no-work day
for the majority of the community. It can be qualified to indicate the
community, as in "family holiday" or "personal holiday" or "state
holiday".
 
R

Randy Webb

Dr John Stockton said the following on 1/2/2006 9:46 AM:
JRS: In article <[email protected]>, dated
Sun, 1 Jan 2006 13:02:07 local, seen in Randy



Christmas is a holiday throughout the Western world; I don't know
anywhere that has Halloween as a holiday. The normal meaning of holiday
is a no-work day.

Then Christmas, in a WWW context, is not a 100% Holiday anymore than
Rhamadan, Hanukkah or Easter is. All of which are celebrated in the
"Western world" as you put it. Once again, your bias is obvious.
Again an errant apostrophe. Actually, it's quite useful. Jerusalem and
Christianity are strongly linked, and Christmas is certainly celebrated
there. Granted, it is probably not a national Bank Holiday.

OK, substitute the word Rhamadan for Christmas. The point is the same,
you just avoided it.
 
I

Ivan Marsh

BTW, unless otherwise qualified, the term "holiday" means a no-work day
for the majority of the community. It can be qualified to indicate the
community, as in "family holiday" or "personal holiday" or "state
holiday".

Uh... I'm afraid I'm another one that has to disagree with you there.
Holiday means a day of some significance and has nothing to do with a day
off of work.

Your definition would be business and non-business days in these parts.
 
V

VK

Dr said:
The Anniversary of the Battle of the Boyne is, however, a local holiday.

Still the idea that at St. Patrick's Day we would be all accused in a
mercifullless
killing of someone Dr John Stockton makes me all unhappy. The stout
gets too bitter of it.
Do we have any better alternatives? Any browing ideas?
 
M

Matt Kruse

Dr said:
BTW, unless otherwise qualified, the term "holiday" means a no-work
day for the majority of the community.

If halloween isn't a holiday, then what do you call it?
 
M

Matt Kruse

Jim said:
Er. halloween?

It has no classification? Along with Valentine's Day, St. Patrick's Day,
Mother's Day, Father's Day, etc, etc?

Using the definition for holiday as a non-work day leads to inconsistencies.
Is Martin Luther King's birthday a holiday? Many employees do not have to
work that day, but many do. Yet it's a "federal holiday" in the US. Many
stores are open on Christmas, and people need to work. Even though it's a
federal holiday, is it not a holiday for them?

I think most reasonable people lump all these together under the term
"holiday". If the govt recognizes it, it's a "federal holiday" but that
doesn't necessarily mean you will get the day off. If your employer gives
you the day off, then it's a "recognized holiday" or something similar.

Not that any of this really matters ;)
 
J

Jim Ley

It has no classification? Along with Valentine's Day, St. Patrick's Day,
Mother's Day, Father's Day, etc, etc?

Not in en-GB that I can think of.
Using the definition for holiday as a non-work day leads to inconsistencies.
Is Martin Luther King's birthday a holiday?

That's not a holiday either, holiday really isn't used in this sense
(we define holiday as a break from usual routine often involving a
trip away), It's probably mostly understood as an American import
meaning just Christmas.

We use Bank Holiday for days which people generally have off, (but
that is used purely as a phrase)
I think most reasonable people lump all these together under the term
"holiday".

I'm pretty sure that's en-US usage. Wikipedia seems to agree
http://en.wikipedia.org/wiki/Holiday

Jim.
 
D

Dr John Stockton

JRS: In article <[email protected]>
, dated Tue, 3 Jan 2006 11:04:47 local, seen in
news:comp.lang.javascript said:
Still the idea that at St. Patrick's Day we would be all accused in a
....

St Patrick's Day is March 17th. It provides a holiday in both parts of
Ireland (and, for all I know, in New York too).

The Anniversary of the Battle of the Boyne is July 12th, and provides a
holiday only in Northern Ireland.

You are confused, and have not used available data.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,173
Latest member
GeraldReund
Top