# Best way to detect missing images from javascript?

**URL:** <https://www.ruby-forum.com/t/best-way-to-detect-missing-images-from-javascript/78642>\
**Category:** Rails\
**Created:** [December 7, 2006, 3:43pm UTC](https://www.ruby-forum.com/t/best-way-to-detect-missing-images-from-javascript/78642 "2006-12-07T15:43:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [December 7, 2006, 3:43pm UTC](https://www.ruby-forum.com/t/best-way-to-detect-missing-images-from-javascript/78642/1 "2006-12-07T15:43:01Z")

</div>

Hi

I have a rails app where I need to display images coming from other  
sites.

Does anyone have an effective solution to detect missing images (ie  
broken  
links) in javascript ?

thanks

Thibaut

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [December 7, 2006, 4:07pm UTC](https://www.ruby-forum.com/t/best-way-to-detect-missing-images-from-javascript/78642/2 "2006-12-07T16:07:10Z")

</div>

> I have a rails app where I need to display images coming from other sites.
> 
> Does anyone have an effective solution to detect missing images (ie broken  
> links) in javascript ?

My memory is you can load it up doing something like:

i = new Image;  
i.src = “http://…”;

then check for the resulting size if it’s width or height is zero, it  
isn’t there… and I think there’s a loaded() and maybe other functions  
as  
well…

search for javascript image methods on google and see what comes up…

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [December 7, 2006, 4:11pm UTC](https://www.ruby-forum.com/t/best-way-to-detect-missing-images-from-javascript/78642/3 "2006-12-07T16:11:11Z")

</div>

Hi Philip

thanks for your answer. I finally found this which seems to work just  
fine:

![](http://example.com/testimage.gif)

thanks for the pointer!

Thibaut
