Skip to content

Instantly share code, notes, and snippets.

@jussi-kalliokoski
Created April 20, 2012 07:39
Show Gist options
  • Save jussi-kalliokoski/2426871 to your computer and use it in GitHub Desktop.
Save jussi-kalliokoski/2426871 to your computer and use it in GitHub Desktop.
Detects whether an url is an image
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