Hi everyone
I'm looking for a way to reload a webcam image every 5-10 seconds, but I don't want to be refreshing the whole page with a basic meta-refresh.
I'm not great with Javascript, other than for basic form validation stuff, but the following code is giving me a confusing error in FireFox 2
This is what I've tried to get so far:
<html>
<head>
<script type="text/javascript">
function webcam_reload() {
var newImg = new Image();
newImg.src = 'cam1.jpg?';
newImg.onload = function () {
var theImg = document.getElementById('webcamimg');
theImg.src = newImg.src;
}
theImg = null;
newImg = null;
}
setInterval("webcam_reload()", 1000);
</script>
</head>
<body>
<script>
</script>
<img src="cam1.jpg" alt="" border="0" name="webcamimg" id="webcamimg" />
</body>
</html>
The error I'm getting is:
Error: newImg has no properties
Source File: webcam.html
Line: 13
Is there anyone out there who knows what the problem is?
Or is there an alternative technique I should be looking at?
Thanks, Ben