I want to check if an image exists on the given URL using jquery. For example how do I check that an image exists on this url.
https://www.google.com/logos/2012/hertz-2011-hp.gif
but not on this url
http://www.google.com
function IsValidImageUrl(url) {
$("<img>", {
src: url,
error: function() { alert(url + ': ' + false); },
load: function() { alert(url + ': ' + true); }
});
}
IsValidImageUrl("https://www.google.com/logos/2012/hertz-2011-hp.gif");
IsValidImageUrl("http://google.com");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With