Replace dead images with another - jQuery? [duplicate]
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?
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 ?
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
精彩评论