开发者

Detect HTTP status code when linking to external images

开发者 https://www.devze.com 2023-03-25 00:16 出处:网络
My rails app contai开发者_StackOverflowns something like the following in a view template <%= image_tag \'http://foo.com/images/1\' %>

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

精彩评论

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

关注公众号