鍍金池/ 問答/Linux/ nginx如何把網(wǎng)站中引用的不存在的外部圖片鏈接替換

nginx如何把網(wǎng)站中引用的不存在的外部圖片鏈接替換

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <h1>Test</h1>
    <img src="https://www.baidu.com/files/vender_pic/24115.png">
</div>
</body>
</html>

當(dāng) https://www.baidu.com/files/vender_pic/24115.png 不存在時(shí),替換成 localhost/images/default.png??

回答
編輯回答
厭惡我

和 nginx 沒關(guān)系也做不到,在 img 添加 onerror 事件即可
大概如下所示

function nofind(){ 
    var img=event.srcElement; 
    img.src="/images/default.png"; 
    img.onerror=null; 控制不要一直跳動(dòng) 
} 
<img src="https://www.baidu.com/files/vender_pic/24115.png" onerror="nofind();" />
2018年7月1日 09:15