【发布时间】:2012-02-07 22:04:58
【问题描述】:
加载 Youtube 托管视频的缩略图时,404 错误是实际图像。例如: http://i.ytimg.com/vi/eMFYg2oZ4qE/default.jpg http://i.ytimg.com/vi/0/default.jpg
由于错误显示为真实图像,
<img onerror="alert('error!')" src="http://i.ytimg.com/vi/0/default.jpg">
无法捕捉 404 错误...我该如何解决这个问题?
【问题讨论】:
-
我不确定
onerror应该做什么,因为它的 html 无效,但是这个关于使用 php 处理图像错误的问题可能会有所帮助:stackoverflow.com/questions/1025065/why-wont-this-code-work -
onerror有效。 theglenbot.com/html-image-tag-onerror-attribute -
onerror 很好,但就像我在下面的评论中一样,从技术上讲,它不是 404,它只是来自 YouTube 服务器的默认响应。
-
其实我自己也在想这个……
标签: jquery error-handling youtube http-status-code-404 image