Created
August 17, 2017 22:55
-
-
Save yaci/29bb5beada847d595255ceecacddb6dc to your computer and use it in GitHub Desktop.
Check if all images on page are loaded using 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
//WARNING! May not work with some SVG images | |
//For some SVGs the naturalWidth/naturalHeight attributes will equal 0 | |
//even if image is properly loaded | |
var allLoaded=true; | |
var images = document.images; | |
// or: var images = document.getElementsByTagName('img'); | |
for (i=0; (i<images.length) && allLoaded; i++) { | |
result = images[i].complete && (typeof images[i].naturalWidth!="undefined" && images[i].naturalWidth>0); | |
allLoaded=allLoaded && result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment