Forum Moderators: open
do {
document.slideshow.src = NewImg[ImgNum];
}
while (document.slideshow.onerror == true);
But the loop does not execute a subsequent time if the file does not exist. What am I doing wrong?
Thanks
Tom
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
image1 = new Array("invalid-image1.jpg","invalid-image2.jpg","valid.jpg")
imgNo=0
function newImage1() {
imgNo+=1
document.getElementById("image1").innerHTML='<img src="'+image1[imgNo]+'" onError="newImage1()">'
if (imgNo>image1.length) {document.getElementById("image1").innerHTML='no valid images!';return}
}
//-->
</script>
</head>
<body>
<span id="image1">
<img src="invalid-image1.jpg" onError="newImage1()">
</span>
</body>
</html>
I think onerror is a MS special and not supported by Firefox and perhaps other browsers.
function checkImage(url)
{
var img = new Image;
img.onerror = img_onError;
img.src = url;
}function img_onError()
{
alert(this.src);
}
However, I can never get it to work in Mozilla. I can't even work out from the (sparse) documentation whether the event is supported on images at all.
A workaround could involve using onload, and a timeout with a presumed "if it ain't here by now, it ain't coming ever" time allocation.
I tried the example I posted earlier, but this time on a page on my local server, and it worked. So it seems that it does work in Moz, but not over the file: protocol. ie You can't test it on your PC's file system.