473,385 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

img onload broken in IE?

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
3 11369
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Pai | last post by:
hello there, I am trying to rersize the window it works find in IE but doea not work with mozilla window.attachEvent(onload,MWSOnLoad); window.onload = function (MWSOnLoad) { alert('hello');...
2
by: sonic | last post by:
Hi, I have some code attached to window.onload event and if there is a missing flash file on the page for example, the browser (MSIE in my case) displays "1 item(s) remaining" message, and since...
2
by: inevercheckthisaddress | last post by:
I can't get Opera to fire an event when an image object's src has loaded. The test code I'm using is this - --------------------------------- window.onload=go function yo() { alert("yo"); }
1
by: Andrew Poulos | last post by:
Whenever the content of a frame ('mainFrame') has loaded I call a function. The following code works in IE 5.5+ but IE 5 does nothing (I have a different technique for MZ, FF...): window.onload...
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
5
by: Andy Fish | last post by:
Hi, I have an asp.net web application which uses a pop-up form that works a bit like a dialog box. when the user clicks "OK" it does a postback (basically a form post if you don't know .net) to...
1
by: quickcur | last post by:
Hi all, What happend to the onload event of <img src=myimage.jpgtag if the myimage.jpg is not available? My feeling is that the onload is not called at all. How can I capture the event if the...
3
by: jon | last post by:
Hello, I've had long standing code that runs in IE, that I'm testing with firefox unsuccessfully now. The problem seems to be that images that I dynamically create don't fire their onload event...
20
by: Mark Anderson | last post by:
Hi, I have this in an external JS library: ///////////////////////// function addMyEvent(){ var obj; if(document.attachEvent) { obj = document.getElementsByTagName('img'); for...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.