Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple HTML with automatic image refresh

Status
Not open for further replies.

JASONHEADSETSDOTCOM

Programmer
Oct 17, 2015
1
IN
Hi,

I am very new javascript and webpage development. Can you please help me with following webpage ?

The webpage should contain a simple image element which should refresh with the most recent image in a directory. Can someone please share the required HTML and javascript code for the same ?
 
forum215
forum253

<meta http-equiv="refresh" content="5"> Refreshes the page every five seconds.

Makes it completely useless for visitors as does ANY automatic refresh system.


What you need is NOT managed by javascript but needs to be set on your server (cache headers and expiry times.)




Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Your request does not really make sense.

Javascript generally has no access to directory functions either on the server or on the client. So no way for it to really tell if an image file is new or not in any way.

Usually, as Chris points out, this is done via html headers in the website code. That tell the browser to go fetch the image every time, instead of using its local cache. Which means if the image file is updated, it will be loaded from server every time (assuming the image keeps the same file name).

If you are adding image files with different names and always want the newest one, that would be more server side code task such as PHP or ASP. But definitely not Javascript.











----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
But definitely not Javascript.
Well you could add a dynamic unique query string var to the img source path to create an un-cached URL.

I use this technique server side to add a version number GET argument to resources, so the browser is forced to reload a script or css to ensure latest version is being used.



"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
 
Hi

1DMF said:
But definitely not Javascript.
Well you could add a dynamic unique query string var to the img source path to create an un-cached URL.
Given that
JASONHEADSETSDOTCOM said:
refresh with the most recent image in a directory
how will JavaScript alone guess the name of the latest image file ?

( Of course, if the question actually means "refresh with the most recent content of the same image file in a directory", then is indeed doable with JavaScript alone. )


Feherke.
feherke.ga
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top