Edit in JSFiddle


              
            
          
            
              
                
function validate(url) {
    return new Promise(
        function(resolve, reject) {  
         if ('onload' in document.createElement('link')) {
           var link = document.createElement('link');
           link.rel = 'prefetch';
           link.onload = function() { resolve('Valid URL ' + url) };
           link.onerror = function() { reject('Invalid URL ' + url) };
           link.href = url;
           document.head.appendChild(link);
 	         } else {
             reject('Not supported link onload')
           }
  			}      
    );
}

function ok(txt) {
  document.body.innerHTML += '<p style="color:green">' + txt + '</p>';
}

function err(txt) {
  document.body.innerHTML += '<p style="color:red">' + txt + '</p>';
}

validate('http://google').then(ok).catch(err);
validate('http://google.com').then(ok).catch(err);
validate('https://google.com').then(ok).catch(err);
validate('http://yahoo.cox').then(ok).catch(err);
validate('https://facebook.com').then(ok).catch(err);
validate('https://flickr.com').then(ok).catch(err);