0

Possible Duplicate:
jQuery/Javascript to replace broken images

Not sure how possible this is but I would like to have dead images replaced with another such as missing.jpg or something to that effect. Is this possible?

Community
  • 1
  • 1
Bob
  • 21
  • 2
  • 2
    Look at this question which asks the same - http://stackoverflow.com/questions/92720/jquery-javascript-to-replace-broken-images – Kasaku Sep 08 '11 at 10:41

2 Answers2

4

Add the following to your .htaccess :

RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule \.(gif|jpe?g|png|bmp) /path/to/logo.gif [NC,L]

Although this is not a JQuery answer ... do you specifically require JQuery to resolve this issue ?

Manse
  • 37,765
  • 10
  • 83
  • 108
1

You could use the onerror event to assign the image a new path:

function ImgError(source){
    source.src = "/images/noimage.gif";
    source.onerror = "";
    return true;
}

<img src="someimage.png" onerror="ImgError(this);"/>

Source: jQuery/JavaScript to replace broken images

Community
  • 1
  • 1
Clive
  • 36,918
  • 8
  • 87
  • 113