0

I got below jquery snippets for check the image are loaded and its working fine, I want to know any possibility to check the else case like image is not loaded with below snippet.

<img id="proPic" src="">
$('#proPic').attr('src', imgurl).load(function() {
     alert('Image Loaded');
    });
Cœur
  • 37,241
  • 25
  • 195
  • 267
Jaison James
  • 4,414
  • 4
  • 42
  • 54
  • may you try to execute the script like: if image exists than start a timer and give this timer e.g. 4 sec to check if image loaded – Dwza Sep 15 '14 at 05:45
  • you may check this accepted answere here http://stackoverflow.com/questions/3537469/jquery-detect-when-image-has-loaded – Dwza Sep 15 '14 at 05:52

1 Answers1

1

you can use jquery error() to achieve this task, try following:

$('img').error(function() {
    this.src = 'some_default_image_source';
});
Hiren Kagrana
  • 912
  • 8
  • 21
  • i think i tried this one in the past and ran into some probems. Check szenarios like: Image is e.g. 5mb or bigger and takes time to load.... – Dwza Sep 15 '14 at 05:49