Skip to content

Instantly share code, notes, and snippets.

@flesch
Last active October 30, 2015 19:24
Show Gist options
  • Save flesch/c6d3d9628e46bfc3e8c9 to your computer and use it in GitHub Desktop.
Save flesch/c6d3d9628e46bfc3e8c9 to your computer and use it in GitHub Desktop.
var domains = ['vztube.verizon.com', 'vztube.vzwcorp.com', 'vztube.verizonwireless.com'];
function getFirstAccessibleDomain(callback) {
var domain = domains.shift();
var image = document.createElement('img');
image.onload = function(){ callback(null, domain); };
image.onerror = function(){
if (domains.length) {
getFirstAccessibleDomain(callback);
} else {
callback(new Error('No domains acessible.'), null);
}
};
image.src = 'https://' + domain + '/images/spacer.gif?cache=' + (+new Date()) + '&referrer=' + encodeURIComponent(window.location.href);
}
getFirstAccessibleDomain(function(err, domain){
console.log(err, domain);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment