Inputting a Default Image in Case the Src Attribute of an HTML ≪Img≫ Is Not Valid

Inputting a default image in case the src attribute of an html img is not valid?

You asked for an HTML only solution...

 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"   "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head> <title>Object Test</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
<p> <object data="http://stackoverflow.com/does-not-exist.png" type="image/png"> <img src="https://cdn.sstatic.net/Img/unified/sprites.svg?v=e5e58ae7df45" alt="Stack Overflow logo and icons and such"> </object> </p>
</body>
</html>

Inputting a default image in case the src attribute of an html img is not valid?

You asked for an HTML only solution...

 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"   "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head> <title>Object Test</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
<p> <object data="http://stackoverflow.com/does-not-exist.png" type="image/png"> <img src="https://cdn.sstatic.net/Img/unified/sprites.svg?v=e5e58ae7df45" alt="Stack Overflow logo and icons and such"> </object> </p>
</body>
</html>

Image found on src attribute but not loaded

For some reason, the image' relative path (./) is the public folder. Thank you all!

Set a default value for Image src in next.js

In my case, the right way to do that is by onErrorCapture.



Related Topics



Leave a reply



Submit