Good day! I use the onError JavaScript event in <img> tags:

 < img src="test.ru/img1.jpg" onError="fc_error()"> 

The question is: how do you know the status of the error with which the event was caused? That is, find out the error "404 Not Found" or "net::ERR\_INTERNET\_DISCONNECTED" . The main thing for me is to know if the error was 404 or not.

Tell me how to find out. Thank you in advance.

    2 answers 2

    Finally it dawned on me that it was necessary to get exactly the HTTP response code of the request, when downloading a picture, if everything is good: 200, if everything is bad, then type: 404.

    The answer to your question: it can not be done . Throw a stone at me if it can be done. And why, if there are convenient means for this?

    Therefore, I do not understand why the standard options do not suit you, but you can always use them: AJAX, GET, XHR, new Image, as well as the terrible inline script onerror to check the validity of loading images.

    Actually, it seems to me that you did not accept what I proposed, as a solution, and there is a solution that you need.

    • I thought it was possible to read the console through js - PicanTo
    • @PicanTo, yes, if an error uploads a picture, an error code is written to the console, but firstly it is not a cross-browser solution, secondly, the author needs to do this through an inline script, thirdly, this is nonsense, because there are 1001 ways to do it without distortions. - Ilja
    • @PicanTo, if the author still told what for he needs it at all, maybe I would not be so categorical. - Ilja

    I don’t understand much about JS, but perhaps this is what you need: http://learn.javascript.ru/onload-onerror

    • No it's not that. It does not explain how to find the error status. - PicanTo
    • How not to explain? An error message is sent to the callback. - user31688