473,378 Members | 1,449 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Scheduled image substitution

Hello...

I have a website that hosts a java chat room nightly. I'd like to have
a graphic on the main page that toggles between 2 images - one
advertising the time of the chat, and another that appears during the
time the chat is actually in session inviting visitors to the web site
to join the chat.

Any idea how I might do this in Javascript to schedule the imgage
substitution using a general meridian time function?
Thanks for your suggestions!

Jul 23 '05 #1
5 1447
go****@ghosthounds.com wrote:
Hello...

I have a website that hosts a java chat room nightly. I'd like to have
a graphic on the main page that toggles between 2 images - one
advertising the time of the chat, and another that appears during the
time the chat is actually in session inviting visitors to the web site
to join the chat.

Any idea how I might do this in Javascript to schedule the imgage
substitution using a general meridian time function?
Thanks for your suggestions!


Presumably the image changes based on the time at the server's
location? Why not just have a script on your server that at a
specified time replaces one image with the other?

You have two source images: a.gif and b.gif. The image in the page is
c.gif. At the specified time for chat to start, your server script
copies a.gif to c.gif. At the next specified time, when chat ends,
b.gif is copied to c.gif, and so /ad infinitum/.

Maybe you need to "touch" the image to update the file creation time so
cached images will update c.gif if you've changed it (but I don't think
so).

Look ma, no JavaScript!

--
Cheers, Rob.
Jul 23 '05 #2
RobG wrote:
Why not just have a script on your server that at a
specified time replaces one image with the other?
Because I'm even less familiar with server side scripting than I am
with Javascript. ;)
You have two source images: a.gif and b.gif. The image in the page is c.gif. At the specified time for chat to start, your server script
copies a.gif to c.gif. At the next specified time, when chat ends,
b.gif is copied to c.gif, and so /ad infinitum/.

Maybe you need to "touch" the image to update the file creation time so cached images will update c.gif if you've changed it (but I don't think so).


Hmmm... that seems extreme overkill for what I'm wanting to do. Maybe
I wasn't clear in my original description, but all I want is a very
basic javascript that, when the page is loaded, displays A.GIF for 22
out of the 24 hours in a day. Except if the page is loaded, between
say UTC 03 and UTC 05 - then it swaps the image with B.GIF

Is a server side script really the better way to do that? I'm not
really concerned that everyone has to see the "Chat now" image at
exactly the same time - I.E. the time on the users PC is fine for the
javascript to get the time from. Unless it can be called from the
server itself in the javascript easily.

Thanks for your input! :)

Jul 23 '05 #3
JRS: In article <11**********************@z14g2000cwz.googlegroups .com>
, dated Mon, 13 Dec 2004 16:06:52, seen in news:comp.lang.javascript,
go****@ghosthounds.com posted :

I have a website that hosts a java chat room nightly. I'd like to have
a graphic on the main page that toggles between 2 images - one
advertising the time of the chat, and another that appears during the
time the chat is actually in session inviting visitors to the web site
to join the chat.

Any idea how I might do this in Javascript to schedule the imgage
substitution using a general meridian time function?
Thanks for your suggestions!

T = new Date().getUTCHours()
src = ['a', 'b'][+(T>=20 && T<22)] + ".gif"

will compute the name of the image to load, changing at 20h & 22h UTC.

new Date()%864e5/36e5|0 // also gets UTC hour-of-day; note |

If you want a Web page to change dynamically when the user's machine
thinks the UTC is right,

new Date()%864e5 // UTC millisecond-of-day

can be used to compute the exact interval to the next status change, for
a setTimeout to load the new image and recompute the interval.

To be more exact, given the potential for user clock adjustment,
calculate the image letter index once a minute and see if it has
changed.

If the times are not whole hours, divide by 6e4 instead to get minute of
UTC day.

BTW, not that it affects you, ISTM that a server cannot initially know
the user's local time, but it may be able to get javascript to send it
the user's offset from GMT.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #4
RobG wrote:
Why not just have a script on your server that at a
specified time replaces one image with the other?
Because I'm even less familiar with server side scripting than I am
with Javascript. ;)
You have two source images: a.gif and b.gif. The image in the page is c.gif. At the specified time for chat to start, your server script
copies a.gif to c.gif. At the next specified time, when chat ends,
b.gif is copied to c.gif, and so /ad infinitum/.

Maybe you need to "touch" the image to update the file creation time so cached images will update c.gif if you've changed it (but I don't think so).


Hmmm... that seems extreme overkill for what I'm wanting to do. Maybe
I wasn't clear in my original description, but all I want is a very
basic javascript that, when the page is loaded, displays A.GIF for 22
out of the 24 hours in a day. Except if the page is loaded, between
say UTC 03 and UTC 05 - then it swaps the image with B.GIF

Is a server side script really the better way to do that? I'm not
really concerned that everyone has to see the "Chat now" image at
exactly the same time - I.E. the time on the users PC is fine for the
javascript to get the time from. Unless it can be called from the
server itself in the javascript easily.

Thanks for your input! :)

Jul 23 '05 #5
wrote on 15 dec 2004 in comp.lang.javascript:
Maybe
I wasn't clear in my original description, but all I want is a very
basic javascript that, when the page is loaded, displays A.GIF for 22
out of the 24 hours in a day. Except if the page is loaded, between
say UTC 03 and UTC 05 - then it swaps the image with B.GIF


<script type='text/javascript'>
function lookfortime(){
t= new Date()
t= t.getUTCHours()
if(t>2&&t<5)
document.getElementById('a').src='b.gif'
else
document.getElementById('a').src='a.gif'

setTimeout('lookfortime()',60000)
}
</script>

<body onload='lookfortime()'>
<img src='a.gif' id=a>

NOT TESTED

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: rmk | last post by:
Hi, I have a 404 error handler that can redirect when a url is mistyped or when a page has moved. I would like to have the same control for images. For example: photo/1234-Kitchen.jpg ...
5
by: A. Lovhaug | last post by:
I have a console application built in the .NET Framework. This application basically executes an XCopy based on parameters that I pass to it. I use it for creating scripts for backing up folders,...
6
by: John Bowman | last post by:
Hi, I have a C# app that needs to launch the "Add Scheduled Tasks" wizard found in the control panel "Scheduled Tasks" applet. I realize that this "applet" really just opens the tasks folder,...
1
by: Ching-Lung | last post by:
Hi, How can I manually run a win scheduled task (*.job) from C# or through command prompt? Please advice, thanks! -CL
5
by: Murali | last post by:
In Python, dictionaries can have any hashable value as a string. In particular I can say d = {} d = "Right" d = "Wrong" d = "test" In order to print "test" using % substitution I can say
1
by: satelite | last post by:
Hello, I am writing an exe that is intended to be run via a scheduled task. However, I also need the flexibility to have users run the scheduled task manually (right click task and select run). ...
1
by: Myster Edd | last post by:
I have a strange problem that I think deals with security on SQL 2005. I have a scheduled task that runs on a Windows 2000 machine. It calls a vb script which creates a connection to SQL Server. ...
0
by: Paulson | last post by:
Dear Freinds I want to make a program that acts as a reminder for the users.I need to open up the Scheduled task wizard programmatically.If you type Tasks in the run command the Tasks...
9
by: jdaelhousen | last post by:
I have a bit of a problem I'm hoping someone can shed some light on... I have a VB.Net console application written in VS 2003 that produces a .exe file that now sits on a Windows 2000 server...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.