This error is thrown when my site is used inside an organization that blocks certain domains - i.e. social sites etc. They are just links to images on these domains using <img src = "">
From Chrome Console
Failed to load resource: the server responded with a status of 403 (Forbidden: category denied) "Followed by URL"
How can I detect this error pragmatically and have a default image display instead?
This error is thrown when my site is used inside an organization that blocks certain domains - i.e. social sites etc. They are just links to images on these domains using <img src = "">
From Chrome Console
Failed to load resource: the server responded with a status of 403 (Forbidden: category denied) "Followed by URL"
How can I detect this error pragmatically and have a default image display instead?
Share Improve this question edited May 3, 2013 at 15:53 asked Mar 19, 2013 at 15:41 user1637281user16372813 Answers
Reset to default 4I found this:
function imgError(image){
image.onerror = "";
image.src = "/images/noimage.gif";
return true;
}
<img src="someimage.png" onerror="imgError(this);"/>
If you use jquery you can do:
$("img").error(function(){
$(this).attr("src", "default-image.png");
});
You can use the onerror
attribute to execute JavaScript function to change the src
attribute.
http://www.w3schools./jsref/event_img_onerror.asp