How to detect if the image path is broken?
<p>I am trying to detect if the image is available in <code>javascript</code>.</p>

<p>I have a switch statement which return different type of images.</p>

<pre><code>switch (type){

case 'oldProduct':
return "&lt;img src='project/'" + folder + imagename + "/&gt;"
break;

case 'newProduct':
return "&lt;img src='project/'" + folder2 + imagename2 + "/&gt;"
break;

more cases....

}
</code></pre>

<p>I was wondering if there are anyways to detect if the images exist before I return the image. <code>&lt;img src='project/'" + folder2 + imagename2 + "/img&gt; src</code> could be a broken path in my case. Thanks a lot!</p>
