Last active
April 19, 2017 13:42
-
-
Save Ashkanph/a08a789408dc83f776f1f81f24af748b to your computer and use it in GitHub Desktop.
Javascript and HTML code to handle the situations when the image can not be found
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* How to use it in html: | |
* <img src='http://www.example.com/images/hi.jpg' onerror='imageNotFound(this);'> | |
*/ | |
function imageNotFound(image) { | |
image.onerror = ""; | |
image.src = "../images/no-image.png"; | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment