0

I have a function:

function CanDisplayImage() {
  $("img").on('error', function() {
    // do stuff 
    // and finally return false
    return false;
  });
  // if there weren't any error in displaying image, return true
  return true;
}

That function should check whether image can display correctly or not. I wasn't that function to return true or false, for example when I call that:

CanDisplayImage(); // get true or false

So if there weren't any error it will return true, but if there were error, it won't return false, because the function inside of that function will return false. Do U know how can I make that work?

Joseph
  • 1,676
  • 2
  • 10
  • 20
  • 1
    No, you cannot make that work. The error event is asynchronous. – Bergi Feb 02 '17 at 12:38
  • Have you had a look at the following: http://stackoverflow.com/questions/2611980/return-value-from-nested-function-in-javascript http://stackoverflow.com/questions/2993563/how-do-i-return-a-variable-from-google-maps-javascript-geocoder-callback – ACOMIT001 Feb 02 '17 at 12:39
  • Thanks. That was a good solution. Now I managed to do that. – Joseph Feb 02 '17 at 12:43

0 Answers0