Testing when an Image is Loaded -
07-13-2004
, 12:16 AM
the following script looks for am image in the current directory, and if not
found goes up a level, one by one until the image is found or we are at the
root directoy. It works greatl however sometimes it does not detect the image
unless i place a pause on the line indicated below.
How do I test to see if an image is in the process of loading and when it has
completed loading. In NN there is an onLoad event; how do I do it in IE?
Here is the code.
<script language="JavaScript">
Page_URL = document.URL;URL = "Page_picture.gif";y = Page_URL.length
while (y>4) {
tester=new Image();tester.src=URL;
// need a slight pause to load file
if (tester.fileSize > 0) break
for (y = y; y>1; y--) {
if (Page_URL.charAt(y) == "/") {
URL=Page_URL.slice(0,y)+"/Page_picture.gif"
y--
break
}
}
}
document.write("<img src= '"+tester.src+"' width=\"188\" height=\"188\">")
</script> |