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

Solutions on MaxInterview for how to check if an image exists in js from cross origin by the best coders in the world

showing results for - "how to check if an image exists in js from cross origin"
Giovanni
07 Jul 2020
1      var fileURL = "assets/"+scope.productDirectory+"/content1/info/"+x+".png";
2      imageExists(fileURL, function(exists, url) {
3        if(exists) {
4          scope.contentOneSequence.push(url);
5        }
6      });
7
8     function imageExists(url, callback) {
9      var img = new Image();
10      img.onload = function() { callback(true, url); };
11      img.onerror = function() { callback(false, url); };
12      img.src = url;
13    }
14