开发者

Replace dead images with another - jQuery? [duplicate]

This question already has answers here: 开发者_C百科 Closed 11 years ago.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜