Created
May 17, 2018 08:08
-
-
Save pabloleonalcaide/1e8ece835ea689894dd37a44f0ce7134 to your computer and use it in GitHub Desktop.
Check if a image file exists with Javascript
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
/** | |
* Checking if an image exist in your image folder | |
*/ | |
let loadImage = function(variable){ | |
var image = new Image(); | |
var url_image = './ImageFolder/' + variable + '.jpg'; | |
image.src = url_image; | |
if (image.width == 0) { | |
return `<img src='./ImageFolder/defaultImage.jpg'>`; | |
} else { | |
return `<img src='./ImageFolder/`+variable+`.jpg'`; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment