I am running a online photography portfolio and sometimes, 1 or 2 images on a page fails to load. and refreshing will display the failed to load image.
Scenario: I c
Put below code at end of page:
$('img').error(function(){
var src= $(this).attr('src');
if (window.console) {
console.log('reload image '+ src);
}
var i= src.indexOf("&random=");
if(i > -1) {
src= src.substring(0,i);
}
i = src.indexOf("?random=");
if(i > -1) {
src= src.substring(0,i);
}
if(src.indexOf('?') > -1 ) {
src= src+"&random="+ (new Date().getTime());
} else {
src= src+"?random="+ (new Date().getTime());
}
$(this).attr('src', src);
});