Click to See Complete Forum and Search --> : time-based image swap?


longhorn14
11-10-2003, 10:29 PM
This is sort of a strange question, but here is what I am looking for:
I am designing a site for a radio show, I think it would be cool if I could get an image that says "on air" to display only when the host is on air (10-11, saturdays). Ideally, I would have a normal image with "on air" muted out all the time, except for when the show is on. Anyone have any idea how I might achieve this? Thanks in advance,
nat

Gollum
11-11-2003, 06:02 AM
a little bit of script should do the trick...

<html>
<body>
<script>
<html>
<body>
<script>
var d = new Date();
// need to test time in terms of GMT (UTC) as you don't know where the user might actually be.
// so say you are in Austin TX, which is GMT-6 and your show is from 7pm to 9pm...
if ( (d.getUTCHours() >= 2) && (d.getUTCHours() < 4) )
{
document.write('<img src="onair.jpg">');
}
else
{
document.write('<img src="offair.jpg">');
}
</script>
</body>
</html>

Note, with this code, once the page has loaded, the image is fixed. You will need to do more to have it automatically change at the right time.

longhorn14
11-11-2003, 09:49 AM
Thanks a ton! I will give that a shot and let you know how it goes.
-nat

longhorn14
11-11-2003, 09:37 PM
I got that to work (I am not sure I understand the time offset, but I will monkey with that). How would I get it to work for only Saturday (since the show is only saturday 10-11 am)?
Thanks, I am learning a lot!