-
-
Save cmpscabral/7626ae29475283d32771 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hostReachable() { | |
// Handle IE and more capable browsers | |
var xhr = new ( window.ActiveXObject || XMLHttpRequest )( "Microsoft.XMLHTTP" ); | |
var status; | |
var server = window.location.hostname; | |
if (window.location.port != '') { | |
server += ':'+window.location.port; | |
} | |
// Open new request as a HEAD to the root hostname with a random param to bust the cache | |
xhr.open( "HEAD", "//" + server + "/?rand=" + Math.floor((1 + Math.random()) * 0x10000), false ); | |
// Issue request and handle response | |
try { | |
xhr.send(); | |
return ( xhr.status >= 200 && xhr.status < 300 || xhr.status === 304 ); | |
} catch (error) { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it's Great, Thanks