When trying to display image that's adress doesn't exist you will see default browsers "no image" badge.
How to change it to default "no-image.png" placeholder?
echo "<img src='http://www.google.com/trolol.png'>"; //for example
You can use the onerror attribute, example:
<img src="" onerror="this.src = 'no-image.png';" alt="" />
<img src='http://www.google.com/trolol.png' onerror="this.src='http://jsfiddle.net/img/logo.png'">
sample http://jsfiddle.net/UPdZh/1/
The onerror event is triggered if an error occurs while loading an external file (e.g. a document or an image).
Syntax
<element onerror="SomeJavaScriptCode">
http://wap.w3schools.com/jsref/event_onerror.asp
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