joe said:
Ok. I think I found a solution:
<img src="orig_image.jpg" onerror="this.src='alt_image.jpg';">
This is not a standards compliant solution, though. The `img' element
does not have an `onerror' attribute in Valid (X)HTML markup, and the
`alt' attribute is required. A standards compliant solution, taking
into account additional DOM features, could be
<!-- Transitional HTML or XHTML DOCTYPE, else use `id' instead of `name' -->
<html>
<head>
...
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function replaceOnError(img, alt_src)
{
if (typeof img.onerror != "undefined")
{
img.onerror = function()
{
this.src = alt_src;
return true;
}
}
}
</script>
...
</head>
<body onload="replaceOnError(document.images['foo'], 'alt_image.jpg');">
...
<img src="orig_image.jpg" alt="foo" name="foo">
...
</body>
</html>
But you rather should consider the ErrorDocument directive of httpd
compatible Web servers (like the Apache HTTP Server) which will also
work without client-side script support.
PointedEars