Pick a second image when the first is unavailable

B

Bob Flaminio

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...
 
T

Tom

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
 
T

Thomas 'PointedEars' Lahn

Tom said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top