Skip to content Skip to sidebar Skip to footer

Image Existance Checking Is Not Working

I have used image existence checking code from here. My code looks like: var checkImage = function(src,success) { var img = new Image(); img.onload = function() { success(s

Solution 1:

try this

functionIsValidImageUrl(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");

Solution 2:

you can Use jquery to check whether file exists or not

var checkImage=function(src){

   $.ajax({

      url:src,
      type: "HEAD",
      async: true,
      success: function()
      { 
         //This shows file is there// If it is there load it into your variable
      },
      error: function()
      {
       //file is not there
      },
   });
}

Post a Comment for "Image Existance Checking Is Not Working"