-3

I have an html page contain Image, the image source is locally,

<img src="c:\bla\bla.png" />

so, the "bla.png" file is changed, I overwrite the image,

How can I refresh the image in the img control without refreshing the whole page?

Mohammad Shaban
  • 176
  • 1
  • 16

2 Answers2

3

Try

let url = 'c:\bla\bla.png', 
    count = 0;
setInterval(function() {
    document.getElementById('myimg').src = url + '?cnt=' + count++;
}, 1000);

Change the html a little.

<img id="myimg" src="c:\bla\bla.png" />
Jerinaw
  • 5,260
  • 7
  • 41
  • 54
2

Everytime that the image changes you execute this code:

yourImage.src = "http://localhost/image.jpg?" + new Date().getTime();

If you can't catch this event, just instantiate an interval

setInterval(function(){ yourImage.src = "http://localhost/image.jpg?" + new Date().getTime(); }, 1);
Marco Salerno
  • 5,131
  • 2
  • 12
  • 32