2
I have a website on html where the goal was to update a half-second image with a new one. Like a video surveillance. But I needed to know what the Function in html for the image to change. It may seem a very weak doubt but I am new in programming.
<!DOCTYPE html>
<html lang="en">
<head>
<title> Cam1 </title>
<meta http-equiv="Content-Language" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script>
function GetImage(){
setTimeout(function(){
document.getElementById("img").src = "images/yyy.bmp?t="+Date.now();
},500);
}
</script>
</head>
<body>
<!-- não sei como fazer aqui-->
<img id="img" src="images/yyy.bmp" style="width:304px;height:228px;"/>
</body>
</html>
Your code is right. Just call the function
GetImage
. You can do it like this:<body onload="GetImage()">
. Test to see if that’s what you were looking for. A doubt?t="+Date.now();
why? the server will give new images with this query?– Sergio
@Sergio did what he said and added the onload="Getimage()"> but instead of no body, I added the tag img, when there is your doubt, the code was built through several, and I’m no longer quite sure about what it does, but I know that without it the function cannot make the get of the image
– user88845
"but instead of in the body, I believe in the tag img" - why? In fact it was best to use only the content of the function (only the
setTimeout
) and put this<script>
at the bottom of the page before</body>
. Test and tell if it worked.– Sergio
@Sergio is not working, when I wear the body can simulate and test if I can? and I didn’t quite realize the part of using only the setTimeout
– user88845