Reputation: 1
I try to refresh every 0.7 sec. an image from a webcam.
Before showing the image on the webpage, I preload the image, do some checks on the preloaded image and if everything is okay, want to update the src attribute of the image tag on the page. Unfortunately this does not work
In chrome devtools, I can see that the preload of the images works fine, however the update on the webpage for some reason does not happen.
Any ideas of why this is happening?
Thank you all.
Update 1/6/16 : typo $('test').attr... replaced by $('#test').atrr...
My code :
<img id="test" width="710" height="400"/>
<script>
jQuery(window).ready(Update_Screen);
function Update_Screen(){
setInterval(preload, 700);
};
function preload(){
var my_image = new Image();
var img_path = "/cgi-bin/ZavioCamCGI.py?key=" + (new Date().getTime());
my_image.src = img_path;
var x = true;
if (!my_image.complete) {
x = false;
};
if (typeof my_image.naturalWidth !== "undefined" && my_image.naturalWidth === 0) {
x = false;
};
if (x == true) {
$('#test').attr('src',img_path);
};
};
</script>
Upvotes: 0
Views: 87
Reputation: 8053
$('test').attr('src',img_path);
should be
$('#test').attr('src',img_path);
// ^ missing hashtag sign
Update
After adding the hashtag, your code seems to work fine, see this jsfiddle.
Upvotes: 1