开发者

Detect HTTP status code when linking to external images

My rails app contai开发者_StackOverflowns something like the following in a view template

<%= image_tag 'http://foo.com/images/1' %>

Sometimes, if the url does not contain an image, the hosting site will return a response with a 404 or 302 status.

In this case, the alt-text for the image is displayed.

How can I detect the HTTP response status in order to insert a different image? (such as the next image, or a default 'not found' image)?


Adding :onError => "alert('error')" To the image tag triggers when the image doesn't load.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜