Possible Duplicate:
Check if image exists with given url using jquery
Change image source if file exists
I am throwing the value of an image path from a textbox into boxvalue and want to validate if the image exist using javascript.
var boxvalue = $('#UrlQueueBox').val();
I browsed stackoverflow and found the below to get the image width/height, but don’t want to use this.
var img = document.getElementById('imageid');
How can an I validate if it is really an image from the image path?
The general strategy is to use an DOM
Imageobject instance, set thesrcproperty to the URL of the image you want to check (which will cause the browser to fetch and load the image), and then handle theloadanderrorevents to determine existence or absence, respectively.Here’s an example promise-based approach: