Replace missing image with text

Here's a tiny piece of Javascript which will replace a missing image with it's alt text. You should surround the image with a tag to format the text.

Place this in the <head> section of your HTML:

<script>

function img2txt(img) {

  txt = img.alt;

  img.parentNode.innerHTML=txt;}

</script>

Then in the <body> you can do this:

<h2>

<img src="http://unverse.net/no/image.gif" 

 alt="Missing Image? Turn it to text"

  onError="img2txt(this)" />

</h2>

<p style="float:left">

<img alt="There's something here! "

  src="Non-existent" 

  onError="img2txt(this)"/></p>

<p><==What is there?</p>

Which gives this:

Missing
Image? Turn it to text

 

There's
something here!

<==What is there?

hide menu | Show caps
Google