img onload broken in IE?

Giganews Newsgroups
Subject: img onload broken in IE?
Posted by:  rabbits…@bigmailbox.net (rabbits77)
Date: 8 Jul 2003

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!!

Replies