Hi Everyone,
I have an application I wrote that sends an image file called Temp.jpg and then it renames it to Webcam.jpg. The user will be looking at a html file that refreshes the Webcam.jpg file as it is updated. I upload temp and rename it so they do not see a broken image or partial while it is sent via ftp. My problem is they still see a broken image when webcam.jpg is deleted and before it is replaced.
I found some code to try out to see if the image is complete or not. But must not be working. Here is the code below. Does anyone have a good way to determine if webcam.jpg is available before displaying it? They can see the same image until a new one is replaced.
Thanks!
Code:<body onLoad="holdUp()"> <p> <B>Hello!<P> <img src="http://www.MyDomain.com/webcam.jpg" width="320" name="campic" /> </p> <p></p> </body> <script type="text/javascript"> <!-- // //AJAXCam v0.8b (c) 2005 Douglas Turecek http://www.ajaxcam.com // function holdUp() { // // This function is first called either by an onLoad event in the <body> tag // or some other event, like onClick. // // Set the value of refreshFreq to how often (in seconds) // you want the picture to refresh // refreshFreq=1; // //after the refresh time elapses, go and update the picture // setTimeout("freshPic()", refreshFreq*1000); } function freshPic() { // // Get the source value for the picture // e.g. http://www.mysite.com/doug.jpg and // var currentPath=document.campic.src; // // Declare a new array to put the trimmed part of the source // value in // var tmp=new Image; tmp.src="Webcam.jpg"; if(tmp.complete) { var trimmedPath=new Array(); // // Take everything before a question mark in the source value // and put it in the array we created e.g. doug.jpg?0.32234 becomes // doug.jpg (with the 0.32234 going into the second array spot // trimmedPath=currentPath.split("?"); // // Take the source value and tack a qustion mark followed by a random number // This makes the browser treat it as a new image and not use the cached copy // document.campic.src = trimmedPath[0] + "?" + Math.random(); } else { } // // Go back and wait again. holdUp(); } // --> </script>


Reply With Quote