Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to check if an image exists in js from cross origin

      var fileURL = "assets/"+scope.productDirectory+"/content1/info/"+x+".png";
      imageExists(fileURL, function(exists, url) {
        if(exists) {
          scope.contentOneSequence.push(url);
        }
      });

     function imageExists(url, callback) {
      var img = new Image();
      img.onload = function() { callback(true, url); };
      img.onerror = function() { callback(false, url); };
      img.src = url;
    }
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #check #image #exists #js #cross #origin
ADD COMMENT
Topic
Name
5+7 =