I want to display img1.png. However, if there's an error finding the file, I want the backup missing.png to appear instead. Is there a way in HTML to have if statements or exceptions?
<try>?
<img src="img1.png">
<except error 404>?
<img src="missing.png">
I put a question mark on all the lines that I don't understand what to do.
See the answer here
It says you can do it as below
<img src="img1.png" alt="Image not found" onError="this.onerror=null;this.src='missing.png';" />
where onerror
is a Javascript function. Please refer the docs for more details about onerror
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With