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!

How can I refresh an image without refreshing the whole page? 1

Status
Not open for further replies.

texnut

IS-IT--Management
Jan 11, 2007
97
US
Hello all - I'm very new to web development so please forgive any tech mistakes I might be making ahead of time.

I have a program that writes an image file to disk every 5 secs. It's the same image file. So for example, the file image1.jpg is overwritten every five seconds with new data.

I would like to write a web page around this image such that the image automatically updates itself without the user having to refresh the page.

I'm assuming that AJAX might be the way to go, but I might be totally wrong.

Does anyone know how to do this?

Many thanks in advance
 
Hi

I would say, there is no need for Ajax. Regular JavaScript is enough :
JavaScript:
var reimg
window.onload=function () {
  reimg=document.getElementById('re')
  setInterval(function () {
    reimg.src=reimg.src.replace(/\?.*/,function () {
      return '?'+new Date()
    })
  },5000)
}
HTML:
<img src="yourimage.png?" id="re">

Feherke.
 
Feherke,

Thanks for the code snippet! I'm going to give it a test later in the afternoon and will post back with results. Thanks again!

Salim
 
Feherke, it worked! Thats a load!

Salim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top