【发布时间】:2014-03-21 21:44:12
【问题描述】:
我想隐藏损坏的图像图标,但我使用的图像服务器不会抛出 404 页面,而是将其重定向到它们的替代图像,所以我不能使用传统的 onerror 方法。 如果服务器抛出 404 页面作为响应,此方法效果很好。
<html>
<body>
<div><img src="http://stackoverflow.com/image.jpg" alt="image" onerror="this.style.display='none'"/></div>
</body>
</html>
但在图像 URL 为:http://tinypic.com/someimage.jpg 的情况下 上述方法行不通。因为这是一个 302 响应,它会将其重定向到其他图像。我也想隐藏它。 是否可以以某种方式使用 http 响应作为显示/隐藏图像的条件。
这是上图的http头:
$ curl -I http://tinypic.com/notfound.jpg
HTTP/1.1 302 Found
Server: Apache
Location: http://tinypic.com/images/404.gif
Expires: Fri, 21 Mar 2014 21:33:07 GMT
Cache-Control: max-age=300
Content-Type: text/html; charset=iso-8859-1
Content-Length: 217
Accept-Ranges: bytes
Date: Fri, 21 Mar 2014 21:28:07 GMT
X-Varnish: 1535787681
Age: 0
Via: 1.1 varnish
Connection: keep-alive
X-Varnish-Server: den2tpv01
X-Cache: MISS
现在,我认为可以以某种方式使用 HTTP/1.1 302 Found。有什么建议吗?
【问题讨论】:
标签: image http http-headers