469,315 Members | 1,532 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,315 developers. It's quick & easy.

Pick a second image when the first is unavailable

I have a page where I'm loading some images, but I'm not guaranteed that
they will be available. I'd like to be able to show some other,
guaranteed image in its place rather than just the broken image icon. Is
there a way with javascript to do this?

TIA...

--
Bob
Jul 23 '05 #1
2 1100
Tom

"Bob Flaminio" wrote
I have a page where I'm loading some images, but I'm not guaranteed that
they will be available. I'd like to be able to show some other,
guaranteed image in its place rather than just the broken image icon. Is
there a way with javascript to do this?


Watch the single and double quotes:
<img src="tryme.png" onerror="this.src='default.png';">
HTH
Ivo
Jul 23 '05 #2
Tom wrote:
"Bob Flaminio" wrote
I have a page where I'm loading some images, but I'm not guaranteed
that they will be available. I'd like to be able to show some other,
guaranteed image in its place rather than just the broken image icon.
Is there a way with javascript to do this?


Watch the single and double quotes: <img src="tryme.png"
onerror="this.src='default.png';">


Aside from the fact that there is no "onerror" attribute in Valid HTML
or XHTML, this will not work if support for client-side scripting is not
present, disabled or restricted. Fortunately, (X)HTML provides means to
do exactly that:

<object data="tryme.png" standby="Loading image..." ...>
<img src="default.png" ... alt="Unable to load image">
</object>

Unfortunately, this does not work in all UAs.
PointedEars
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Marek Mänd | last post: by
3 posts views Thread by src_mag | last post: by
6 posts views Thread by nichughes | last post: by
1 post views Thread by fredo | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.