Having read other people\'s questions I thought
window.onload=...
would answer my question. I have tried this but it executes the code the
A little late to the game, but I've found the following method to be the most straightforward:
function waitForImages () {
let isLoading = true
while (isLoading) {
const loading = [].slice.call(document.images).filter(img => img.complete !== true)
if (!loading.length > 0) {
isLoading = true
return
}
}
}
Note that this is blocking code (useful if you're trying to ensure images are loaded in something like phantomjs)