Skip to content

Instantly share code, notes, and snippets.

@MahbbRah
Created May 1, 2019 09:48
Show Gist options
  • Select an option

  • Save MahbbRah/950cada3af7f52155cfa3076bc4c155a to your computer and use it in GitHub Desktop.

Select an option

Save MahbbRah/950cada3af7f52155cfa3076bc4c155a to your computer and use it in GitHub Desktop.
Checking if a image loaded or not via img with js
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