Generally, the image fails to load for 2 reasons:
- An invalid src.
- A poor internet connection.
How to handle that using the onerror event?
Edit: More details:
So, to be more specific, I made a function for my markdown renderer which can render embeds using the image syntax .
The output will be:
<img src="https://example.com" alt="caption" onerror="renderEmbed(this)"></img>
Since the invalid src url will be used to render embeds, a poor connection with a valid url will be a mess.
`.
–
Mar 09 '20 at 11:14
` will load but `fetch('https://www.w3schools.com/images/compatible_chrome.gif')` will throw an access error (`No 'Access-Control-Allow-Origin' header is present on the requested resource. net::ERR_FAILED`) because you cannot read resources from other sites because of multiple security reasons.