How to return to the calling function (the function above). I would like to return true if the file exists when doing UrlExists('file.png') :
function UrlExists(url)
{
    var http = new XMLHttpRequest();
    http.open('HEAD', url, true);
    http.onerror = function(e){
                            //console.log('......onerror: ' + JSON.stringify(e));
                            if (typeof e !== 'undefined'){
                                return false
                            }   
                        };
    http.send();
    return http.onerror();
}
 
    