Alternate image in case of fallha when loading

Asked

Viewed 618 times

3

I’m creating a script that randomly shows an instaram mosaic. I keep the original image Urls in a comic book, but it turns out that sometimes I have image Urls that don’t load because users have deleted the images in instagram.

How best to display an alternative image in case the source image is not found?

1 answer

5


Okay, searching a little I found the parameter onError executing a script when the image does not require.

<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: http://www.quirksmode.org/dom/events/error.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.