Created
April 14, 2014 06:00
-
-
Save ericvicenti/10620006 to your computer and use it in GitHub Desktop.
browser-side check url for image
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
module.exports = function checkUrlForImage(url, cb) { | |
var doc = window.document; | |
var img = doc.createElement('img'); | |
img.onload = function() { cb(true); } | |
img.onerror = function() { cb(false); } | |
img.setAttribute('src', url); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment