Alternative image in case of load failure

3

I am creating a script that randomly shows a mosaic of urged. I keep the URLs of the original image in a DB, but it happens that sometimes I have image URLs that do not upload because the users deleted the images in instagram.

What is the best way to display an alternate image in case the source image is not found?

    
asked by anonymous 12.02.2016 / 01:04

1 answer

5

Ok, by searching a bit I found the onError parameter that executes a script when the image does not load.

<img src="imagem.jpg" onError="this.onerror=null;this.src='/imagens/semimagem.jpg';" />

Here is also the compatibility table with the list of browsers that support the parameter: link

    
12.02.2016 / 01:04