function testImage(URL) { var tester=new Image(); tester.onload=imageFound; tester.onerror=imageNotFound; tester.src=URL; } function imageFound() { alert('That image is found and loaded'); } function imageNotFound() { alert('That image was not found.'); } testImage("http://foo.com/bar.jpg");
References
https://stackoverflow.com/questions/9815762/detect-when-an-image-fails-to-load-in-javascript
https://www.w3schools.com/jsref/event_onerror.asp