I am trying to check image url:
function testImage(URL) {
var tester=new Image();
tester.onload = function(){ return true}
tester.onerror= function(){ return false}
tester.src=URL;
}
and get that response with this func:
function image() {
var image = $(".image").val();
if(testImage(image)){
$("#display").css({
'background-image' : 'url('+ image +')',
'background-size' : 'cover',
'display' : 'block'
});
} else {
$("#display").css({
'display' : 'none'
});
return true;
}
}
But it doesn't work as for some reason.. Been trying to find the solution for hours.. But If I replace first func code to this:
tester.onload = function(){alert("Yes")}
tester.onerror= function(){ alert("Nope")}
It will show all alerts correctly depending if image url exist or not..
How do I check if testImage function returned true or false so I could implement it properly??