By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,382 Members | 1,637 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,382 IT Pros & Developers. It's quick & easy.

img onload broken in IE?

P: n/a
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!!
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
rabbits77 wrote:
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.

--
David Dorward http://david.us-lot.org/
Redesign in progress: http://stone.thecoreworlds.net/
Microsoft announces IE is dead (so upgrade):
http://minutillo.com/steve/weblog/20...ces-ie-is-dead
Jul 20 '05 #2

P: 2
rabbits77 wrote:
[color=blue]
> theImg.setAttribute("src",imgSrc);[/color]

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

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

--
David Dorward http://david.us-lot.org/
Redesign in progress: http://stone.thecoreworlds.net/
Microsoft announces IE is dead (so upgrade):
http://minutillo.com/steve/weblog/20...ces-ie-is-dead
Actually I'm pretty sure that the onload event does also apply to images...at least, according to the official MS documentation here: link
Jul 24 '06 #3

P: 2
Instead of myImage.setAttribute blah, just do myImage.src = newSourceURL. Also, if this arises in the future, make sure you set the .src attribute of an element after you set the event handlers...
Jul 25 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.