Created
May 1, 2019 09:48
-
-
Save MahbbRah/950cada3af7f52155cfa3076bc4c155a to your computer and use it in GitHub Desktop.
Checking if a image loaded or not via img with js
This file contains hidden or 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
| function checkImage(imageSrc, good, bad) { | |
| var img = new Image(); | |
| img.onload = good; | |
| img.onerror = bad; | |
| img.src = imageSrc; | |
| } | |
| //now we need to run the function written above to see if the image is loaded or not via callback | |
| checkImage( | |
| "image_location.png", | |
| () => console.log('Image loaded Successfully'), | |
| () => console.log('Something went wrong while loading the image!') | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment