Reload

后端 未结 1 544
鱼传尺愫
鱼传尺愫 2021-01-21 14:55

I have an image at the URL http://192.168.1.53/html/cam.jpg (from a Raspberry Pi) and this image is changing very fast (it is from a camera).

So I want to have some Java

1条回答
  •  生来不讨喜
    2021-01-21 15:27

    The problem is that the image src is not altered so the image is not reloaded.

    You need to convince the browser that the image is new. A good trick is to append a timestamp to the url so that it is always considered new.

    function update() {
        var source = 'http://192.168.1.53/html/cam.jpg',
            timestamp = (new Date()).getTime(),
            newUrl = source + '?_=' + timestamp;
        document.getElementById("img").src = newUrl;
        document.getElementById("img1").src =  newUrl;
        setTimeout(update, 1000);
    }
    

    0 讨论(0)
提交回复
热议问题