If an error occurs while loading or rendering an image - (Simple and Useful Solution)

If an error occurs while loading or rendering an image, and an onerror event handler has been set on the error event, that event handler will get called. This can happen in a number of situations, including:

  • The src attribute is empty (" ") or null.
  • The src URL is the same as the URL of the page the user is currently on.
  • The image is corrupted in some way that prevents it from being loaded.
  • The image’s metadata is corrupted in such a way that it’s impossible to retrieve its dimensions, and no dimensions were specified in the element’s attributes.
  • The image is in a format not supported by the user agent.

in this case you can call a default image like no-image.png or etc.

<img  onerror="if (this.src != './images/no-image.png') this.src = './images/no-image.png';" width="128" height="128"  dmx-bind:src="scUserDetail.data.query1.profile_photo">

it was simple but useful for me. I hope it works for you.

4 Likes