/    Sign up×
Community /Pin to ProfileBookmark

time-based image swap?

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

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@GollumNov 11.2003 — a little bit of script should do the trick...
<i>
</i>&lt;html&gt;
&lt;body&gt;
&lt;script&gt;
&lt;html&gt;
&lt;body&gt;
&lt;script&gt;
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() &gt;= 2) &amp;&amp; (d.getUTCHours() &lt; 4) )
{
document.write('&lt;img src="onair.jpg"&gt;');
}
else
{
document.write('&lt;img src="offair.jpg"&gt;');
}
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;

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.
Copy linkTweet thisAlerts:
@longhorn14authorNov 11.2003 — Thanks a ton! I will give that a shot and let you know how it goes.

-nat
Copy linkTweet thisAlerts:
@longhorn14authorNov 12.2003 — 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!
×

Success!

Help @longhorn14 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...