I
I
Ivan Maslov2011-11-28 12:28:59
Internet Explorer
Ivan Maslov, 2011-11-28 12:28:59

Img onerror in IE?

Let's say the image has no path

<img src="" onerror="this.src='/images/anonymous.png'" />

And it is assigned by the system when the application is initialized:
each-structure ...
$(this).attr("src", clientSide.calculateAvatarPath(uId, "small"));


In all browsers, it's fine, but in IE, the onerror handler works even with an empty src and ignores all subsequent path changes! I thought to go the other way - to cheat: each-structure ...
<img src="" />
$(this).attr("src", clientSide.calculateAvatarPath(uId, "small"));
$(this).attr("onerror", "this.src='/images/anonymous.png'");


And what would you think? - the image changes and as soon as it gets "ownership" of the onerror bind - it instantly works! From what? - I can't understand. Help those who know...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anatoly, 2011-11-28
@taliban

When you initialize the application, create a new picture.

H
homm, 2011-11-28
@homm

<img src="" /> - according to the html standard, this is not an img element with an empty picture, it is an img element with a picture, the address of which is equal to the current page.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question