Skip to content

Instantly share code, notes, and snippets.

@welll
Created March 14, 2017 16:12
Show Gist options
  • Save welll/e4bbf930e9befaa91a891f67647db85e to your computer and use it in GitHub Desktop.
Save welll/e4bbf930e9befaa91a891f67647db85e to your computer and use it in GitHub Desktop.
Checking if the image was loaded
function checkIfImageExist(src, cb) {
var img = new Image();
img.onload = function() {
cb(null)
}
img.onerror = function(e) {
cb(new Error('Image ' + src + ' doesnt exist'))
}
img.src = src
}
document.querySelectorAll(`.logo-${size}`).forEach((item) => {
let backgroundImage = window.getComputedStyle(item)['backgroundImage']
backgroundImage = backgroundImage.replace(/url\("/g, '').replace(/"\)/g, '')
if (backgroundImage.indexOf('data:') !== -1) {
return
}
checkIfImageExist(backgroundImage, (err) => {
if (err) {
let div = document.createElement('div')
div.innerHTML = backgroundImage;
body.append(div)
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment