PDA

View Full Version : Image Events


shashgo
10-18-2002, 05:13 PM
I cant figure out when to use imagee event handlers like onLoad(), onError(), onAbort() and complete.

I have a script to test these values for each image that is the src of a pic,

<html>
<head>
<title>Nisha</title>
<script language="javascript">
<!--
var pic=new Image();
for (i=1;i<=20;i++)
{
pic.src=i+".jpg";
alert("Picture name: "+i+".jpg\nonload: "+pic.onload+"\nonerror: "+pic.onerror+"\ncomplete: "+pic.complete+"\nonabort: "+pic.onabort);
}
-->
</script>

</head>
<body>
</body>
</html>

but I cant make head or tail of the results. In the same directory where this script is saved are the images 5.jpg to 8.jpg, 12.jpg to 16.jpg and 19.jpg.

For image 1 to 5, the values are
onload:null, onerror:null, complete:false, onabort:null,

for 6 through 20, the values are
onload:null, onerror:null, complete:true, onabort:null.


Basically, what I want the script to do is to load images that are present and skip over ones that do not exist.

So, it should
*detect that 1.jpg to 4.jpg do not exist (1-4 are not on the disk),
*load 5.jpg to 8.jpg (as those exist)
*skip 9.jpg to 11.jpg (do not exist),
*load 12.jpg to 16.jpg (do exist)
*skip 17.jpg and 18.jpg (do not exist)
*load 19.jpg (does exist)
*skip 20.jpg (does not exist)

I think the way to do this by using these event handlers but I dont know how to use them.

Please help