img onload broken in IE?

R

rabbits77

I have the following:
<html>
<head>
<script TYPE="text/javascript" LANGAUGE="JavaScript">
<!--
function swap (imgID,imgSrc) {
theImg=document.getElementById(imgID);
theImg.setAttribute("src",imgSrc);
}
//--></SCRIPT>
</head>
<body>
<img ID=19 ONLOAD="swap(19,'images/SecondImage.gif')"
src=images/FirstImage.gif>
</body>
</html>

What is supposed to happen is that FirstImage.gif is to be shown and a
call to swap() is made to get SecondImage.gif. While SecondImage.gif
is being generated(in real life it is a dynamically generated image,
not a simple plain gif file) The FirstImage.gif is shown. In
Netscape/Mozilla this works great!! In IE (v5+) What I get is many
repeated calls for SecondImage.gif, as if I have generated some sort
of infinite loop. I have tried changing the swap() function to set the
onload attribute as follows:
function swap (imgID,imgSrc) {
theImg=document.getElementById(imgID);
theImg.onload=noop;
theImg.setAttribute("src",imgSrc);
}

function noop(){

}
Hoping I could trick IE somehow and to a certain extant this works,
after the initial reuqest for SecondImage.gif there are no more,
however, now FirstImage.gif never shows up in IE!! This revision to
the javascript does not bother NS, it continues to work perfectly
fine.
Any insite into this? Any advice at this point would be very much
appreciated!!
 
D

David Dorward

rabbits77 said:
theImg.setAttribute("src",imgSrc);

IIRC - MSIE doesn't support the setAttribute method.
<img ID=19 ONLOAD="swap(19,'images/SecondImage.gif')"
src=images/FirstImage.gif>

The onload event (in HTML) applies only to <body> and <frameset> elements.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top