Skip to content

Instantly share code, notes, and snippets.

@vrkansagara
Created May 16, 2018 03:51
Show Gist options
  • Select an option

  • Save vrkansagara/8bfa6e85fae58e4cd158266777633e9b to your computer and use it in GitHub Desktop.

Select an option

Save vrkansagara/8bfa6e85fae58e4cd158266777633e9b to your computer and use it in GitHub Desktop.
var url = 'https://vrkansagara.in'
documentLinks = document.links
var isHostIsUp = false;
function doesConnectionExist() {
var xhr = new XMLHttpRequest();
var host = url;
xhr.open('HEAD', host, true);
xhr.send();
xhr.addEventListener('readystatechange', processRequest, false);
function processRequest(e) {
console.log("e=>" + e);
if (xhr.readyState == 4) {
if (xhr.status >= 200 && xhr.status < 304) {
isHostIsUp = true;
} else {
isHostIsUp = false
}
alert('==>' + isHostIsUp);
}
return isHostIsUp;
}
alert('asfasfa=>' + isHostIsUp);
}
if (doesConnectionExist()) {
alert('connection exists!');
} else {
alert('connection doesn\'t exist!');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment