Through (native) javascript, i want to check if an image exists. I have found this script:
function imageExists(image_url){
var http = new XMLHttpRequest();
http.open('HEAD', image_url, false);
http.send();
return http.status != 404;
}
from this question. However, everytime i run this, it throws me a HEAD error message whenever it does not find an image (in the console). Can i get rid of this error whenever it fails to find something?
The onload/onerror solution in the comments at the linked question also give me the same issue, with reporting errors.