Javascript image load error handling

There is multiple way to solve the error if image/images fails to load. The easiest solution is to show to a show a default error image. A line of Javascript can easily handle the error!

Inside you image tag just write the following line of code:

onerror="if (this.src != 'source-of-your-error-image.jpg') this.src = 'source-of-your-error-image.jpg';"

That’s all!

2 thoughts to “Javascript image load error handling”

Leave a Reply

Your email address will not be published. Required fields are marked *