I have a website that links to different images on other websites. Sometimes these images have been removed or the domains are no longer live, etc. To not show these images and remove them instead I'm using jQuery to do this:
// catch image load errors
$( "img" ).error(function() {
// read out image source:
var src = $(this).attr('src');
// post the source to the server for the image to be removed
$.post("/pajax/image/notLoaded/", {url:src},
function success(obj) {
if(obj.status =='ok'){
console.log('removed: '+src);
}
},
"json" );
// hide the image & its container div
$( this ).hide();
$( this ).closest(".item-img").hide();
This works fine for images that are no longer live and no data is been sent. However, often enough an HTML page is sent instead in which case jQuery doesn't throw the error, but the console shows "Resource interpreted as Image but transferred with MIME type text/html:"
Is there a way to catch this with jQuery?