jqueryimagedetectbroken-image

Detecting Broken CSS "background-images" in JavaScript/jQuery


Here is an example to detect broken Images
http://maisonbisson.com/blog/post/12150/detecting-broken-images-in-javascript/

but is it possible to detect an broken background-image?
For exmaple:

<div style="background-image:url('http://myimage.de/image.png');"></div>

Solution

  • Do you have control over the "404 not found" page on your server? In that case you could point it to a script that looks for .jpg/.png/.gif in the requested URL and log accordingly, then outputting a 404 page to the user.