I have a code. It is verifying existing of the image. It works perfectly if instead of "return true;" I set "alert("exists");".
With "return true;" it return "undefined"; Why code do not work with "return true;"?
I exetute code like this gallery.VerifyImg("https://jonarhipov.neocities.org/2.png");
var gallery = {
items: [],
ItemsConstructor: function ItemsConstructor(img_url) {
this.img_url = img_url;
},
CreateItem: function LoadImage(i) {
/*
gallery.items[i] = new ItemsConstructor("https://jonarhipov.neocities.org/" + i + ".jpg");
$(".gallery").append("<div class='item' style='background-image: url(" + gallery.items[i].img_url + ")'></div>");*/
},
VerifyImg: function VerifyImg(url) {
var success;
var img = new Image();
img.src = url;
img.onload = function(){return true;};
img.onerror = function(){return false;};
}
}
Thanks!