JavaScript: How do I change my Web page based on time of day?
- 0
- Add a Comment
Dave, I need your help. I’m updating my Web site for The David Lawrence Show and would like to display ‘ON THE AIR’ between 7p and 10p PT (3a to 6a GMT) Monday through Saturday, and ‘OFF THE AIR’ the rest of the time. I can easily replace this displayed text with an image tag once I find an on-air light graphic that doesn’t look like it’s from 1943. How do I do this?
This is a classic situation where you could use a number of different paths to attain the same goal, ranging from a CGI solution to a small server-side include, to a PHP script or, the solution I’ll demonstrate here, a JavaScript client-side snippet.
Each has its strengths and weaknesses, and for JavaScript the risk is that some percentage of your viewers will probably have JavaScript disabled in their browsers. Assuming you can live with only about 95% of your visitors knowing if you’re on the air at that moment, this should work reasonably well, and it’s really easy to add without making any changes on the server.
There’s one other potential hiccup in that since JavaScript is client-side…
Continue reading about JavaScript, Date Objects and HTML (help desk)
