[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

Refresing image in webpage without adding timestamp

IJALAB

8/4/2014 1:40:00 PM

Hi,

I have a webpage in which I need to display the image from flash storage. So, the name of the file cannot be changed. The new image gets updated in the flash but in the web page when I click on the captureimage button, it doesn't get updated with the new image.

This is the code snippet of the capture image.

function CaptureImage() {
setTimeout(function(){
camerascreen= $('#camerascreen') ,
camerascreen.removeattr('src').attr('src',"images/image.jpg");},
4000);
}

can someone help me refresh the image or force display the same image that is in the flash.

thanks,
1 Answer

JJ

8/5/2014 3:09:00 AM

0

On Mon, 4 Aug 2014 06:40:16 -0700 (PDT), balaji.draj@gmail.com wrote:
> Hi,
>
> I have a webpage in which I need to display the image from flash storage. So, the name of the file cannot be changed. The new image gets updated in the flash but in the web page when I click on the captureimage button, it doesn't get updated with the new image.
>
> This is the code snippet of the capture image.
>
> function CaptureImage() {
> setTimeout(function(){
> camerascreen= $('#camerascreen') ,
> camerascreen.removeattr('src').attr('src',"images/image.jpg");},
> 4000);
> }
>
> can someone help me refresh the image or force display the same image that is in the flash.
>
> thanks,

You can use AJAX to reload the image resource, then refresh the image
element's src property. e.g.:

function CaptureImage() {
setTimeout(function() {
var img = document.querySelector("#camerascreen");
if (!img || !(img.tagName === "IMG")) return;
var imgSrc = img.src;
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if ((xhr.readyState === 4) && (xhr.status === 200)) {
img.src = "";
img.src = imgSrc;
}
};
xhr.open("GET", imgSrc, true);
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.send();
}, 4000);
}