Click to See Complete Forum and Search --> : Schedule Image


crash
10-05-2003, 12:14 PM
Does anyone know of a script or can create one to display a different image at different times throughout the day, and 2 different ones on the weekend. I've been searching all over and trying to edit some, but no luck. If you could help that would be awesome!

AdamGundry
10-05-2003, 03:18 PM
Something like this? (You should be able to modify it as appropriate.)

<img src="default.jpg" onload="setImage(this)">

<script type="text/javascript">
function setImage(img){
var now = new Date();
var day = now.getDay();
var hours = now.getHours();

if (day == 0){
img.src = 'sunday.jpg';
} else if (day == 6){
img.src = 'saturday.jpg';
} else if (hours < 7){
img.src = 'before_7_am.jpg';
} else if (hours < 12){
img.src = 'before_12_noon.jpg';
} else if (hours < 19){
img.src = 'before_7_pm.jpg';
} else {
img.src = 'after_7_pm.jpg';
}
}
</script>

Adam

crash
10-05-2003, 03:29 PM
that looks like what i need! i'll see if it works.

thanks so much

AdamGundry
10-05-2003, 03:42 PM
No problem. Well, testing was slightly harder than usual, but what the hey.

Adam

crash
10-07-2003, 04:52 PM
Ok so i was working with it, how do i make two different pictures show on the weekend also, do i just add the time code to the weekend after the day of week?

crash
10-07-2003, 05:35 PM
2 different pictures per day on the weekend..