Skip to content

Instantly share code, notes, and snippets.

@mde
Created April 12, 2011 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mde/916496 to your computer and use it in GitHub Desktop.
Save mde/916496 to your computer and use it in GitHub Desktop.
var assertImageLoaded = function (img) {
var complete = img.complete;
// Workaround for Safari -- it only supports the
// complete attrib on script-created images
if (typeof complete == 'undefined' || complete === false) {
var test = new Image();
// If the original image was successfully loaded,
// src for new one should be pulled from cache
test.src = img.src;
complete = test.complete;
}
// Check the complete attrib. Use strict equality
// check -- don't want undefined, null, etc.
// --------------------------
// False -- Img failed to load in IE/Safari, or is
// still trying to load in FF
if (complete === false) {
return false;
}
// True, but image has no size -- image failed to // load in FF
else if (complete === true &&
img.naturalWidth == 0) { return false;
} // Otherwise all we can do is assume image loaded
else { return true;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment