Created
April 20, 2012 07:39
-
-
Save jussi-kalliokoski/2426871 to your computer and use it in GitHub Desktop.
Detects whether an url is an image
This file contains hidden or 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
function isImage (url, callback) { | |
function cleanup () { | |
delete img.onload; | |
delete img.onerror; | |
img = null; | |
} | |
var img = new Image(); | |
img.onload = function () { | |
cleanup(); | |
callback(true); | |
}; | |
img.onerror = function () { | |
cleanup(); | |
callback(false); | |
}; | |
img.src = url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment