every hour another background image

J

Jomba

Hi everyone,

In folder image i have 24 pictures, and i would like to have some
javascript that will every hour put another picture as background
image.

I would like to do that on this page www.karta-zagreba.com

Tnx everyone!
 
B

Bart Van der Donck

Jomba said:
In folder image i have 24 pictures, and i would like to have some
javascript that will every hour put another picture as background
image.

document.body.style.backgroundImage = 'url('
+ (new Date()).getHours()
+ '.jpg)';

from 00:00 to 00:59 -> 0.jpg
from 01:00 to 01:59 -> 1.jpg
from 02:00 to 02:59 -> 2.jpg
....
from 23:00 to 23:59 -> 23.jpg

This code is preferrably placed in an onLoad-event of the body-tag.

Hope this helps,
 
D

Dr J R Stockton

In comp.lang.javascript message <51dac5b5-f31f-4938-9552-1712a54b21e6@z7
2g2000hsb.googlegroups.com>, Tue, 12 Aug 2008 23:56:59, Jomba
In folder image i have 24 pictures, and i would like to have some
javascript that will every hour put another picture as background
image.

Do you mean for the image to be loaded only with the page, and remain as
long as the page remains displayed, or do you want a new image to be
fetched each hour, in the manner of a clock? To get a good answer, a
good question is required.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
 
I

Ivan

sory, my english is not very well, so I ask only short Q :)

When someone open page, image remain as long as the page displayed.
 
D

Dr J R Stockton

In comp.lang.javascript message <3eb4fa97-80ed-49fb-99c4-4e28f74061f3@34
g2000hsh.googlegroups.com>, Wed, 13 Aug 2008 03:42:28, Bart Van der
Donck said:
document.body.style.backgroundImage = 'url('
+ (new Date()).getHours()
+ '.jpg)';

At a given instant, you and I will see different images. If that is not
wanted, use getUTCHours().

====

I see a bug with Firefox 2.0.0.16 : Menu Help, Check for Updates reports
"There are no new updates available". But <http://www.mozilla-
europe.org/en/firefox/> truthfully says to me "Firefox 3 Free Download
Windows (3.0.1, English (British), 7MB)".
 
P

Paul Lautman

Dr said:
In comp.lang.javascript message


At a given instant, you and I will see different images. If that is
not wanted, use getUTCHours().

====

I see a bug with Firefox 2.0.0.16 : Menu Help, Check for Updates
reports "There are no new updates available". But
<http://www.mozilla- europe.org/en/firefox/> truthfully says to me
"Firefox 3 Free Download Windows (3.0.1, English (British), 7MB)".

How is that a bug? Firefox 3 is not an Update to Firefox 2.
 
R

RobG

Hi everyone,

In folder image i have 24 pictures, and i would like to have some
javascript that will every hour put another picture as background
image.

Have you considered changing the image on the server? Every hour you
could replace say 'background.jpg' with a copy of a different image,
also called 'background.jpg'.
 
E

Evertjan.

RobG wrote on 14 aug 2008 in comp.lang.javascript:
Have you considered changing the image on the server? Every hour you
could replace say 'background.jpg' with a copy of a different image,
also called 'background.jpg'.

Better use dedicated 404.asp for that:

<%
qstr = lcase(Request.ServerVariables("QUERY_STRING"))
if right(qstr,15)="/background.jpg" then
response.redirect "/myDir/myHourPic" & hours(now) & ".jpg"
end if
%>
You have reached my 404 page.
 
E

Evertjan.

Evertjan. wrote on 14 aug 2008 in comp.lang.javascript:
RobG wrote on 14 aug 2008 in comp.lang.javascript:


Better use dedicated 404.asp for that:

<%
qstr = lcase(Request.ServerVariables("QUERY_STRING"))
if right(qstr,15)="/background.jpg" then
response.redirect "/myDir/myHourPic" & hours(now) & ".jpg"
end if
%>
You have reached my 404 page.


Or just do:

<img src='mySwitchingJpg.asp'>

=========== mySwitchingJpg.asp ============
<% 'vbs
Response.Expires = -100
response.redirect "/myDir/myHourPic" & hours(now) & ".jpg"
%>
===========================================

sorry vbs, OT.
 

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,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top