link de verificação do js se existir

//checking link
function urlExists(url, callback) {
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            callback(xhr.status < 400);
        }
    };
    xhr.open('HEAD', url);
    xhr.send();
}


// run function
function check_link(url) {
    urlExists(url, function (exists) {
        if (exists) {
            console.log('"%s" exists?', url, exists);
        }
    });
}
Ivan Cuaco