PDA

View Full Version : onError problem in IE



tech_support
05-11-2007, 08:13 AM
I can't get IE to use onError="alert('Connection error.')" on the <img> tag.

I put a non-existing image to test it out but it displayed the [X] instead of the error message.

Am I doing something wrong?
Anyone know why?

codeexploiter
05-11-2007, 09:16 AM
The below code worked for me in IE 7



<img src="" onerror="javascript: alert('connection error');" />

tech_support
05-11-2007, 09:34 AM
Hmm....
Strange.

I'm using


document.images['imgname'].onerror = function() {
alert('Connection Error')
}

and it doesn't seem to want to work in IE.

Stupid IE...

codeexploiter
05-11-2007, 09:54 AM
Seems to be some problems in its implementation. hmmmm

tech_support
05-13-2007, 09:59 AM
Hello...................?

I'm trying to implement it using


document.images['imgname'].setAttribute('onerror','dothis()')

jscheuer1
05-13-2007, 10:29 AM
I'm trying to implement it using


document.images['imgname'].setAttribute('onerror','dothis()')


That one line of code implies that you are probably either adding the onerror attribute after the page or image tag has loaded/been parsed, in which case the error it is set to detect has already happened before the onerror event is added to the tag, or you are attempting to add the event before the tag to which it will be added has been parsed, in which case it will not be added as the tag doesn't yet exist.

You could add the attribute inline (hard coded) as codeexploiter showed (which is invalid in many DOCTYPES) or add it dynamically as you are doing, but wait until after that to set the src attribute of the image (also dynamically).

You could also add the image tag dynamically with the onerror attribute already a part of it.

tech_support
05-14-2007, 08:02 AM
Strange. The image is already loaded.
It's working in every other browser except Internet Explorer.

tech_support
05-16-2007, 08:34 AM
Never mind, problem fixed.