Created
October 20, 2017 19:02
-
-
Save DNA/2192ea69ade1c6c199c8069536011225 to your computer and use it in GitHub Desktop.
check if url is available
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Document</title> | |
<script> | |
document.onreadystatechange = () => { | |
if (document.readyState === 'complete') { | |
let xhr = new XMLHttpRequest(); | |
let serverStatus = document.getElementById('serverStatus'); | |
xhr.open('HEAD', 'https://api.github.com/'); | |
xhr.timeout = 2000; | |
xhr.onload = _ => serverStatus.innerText = 'ONLINE'; | |
xhr.onerror = _ => serverStatus.innerText = 'OFFLINE'; | |
xhr.ontimeout = _ => serverStatus.innerText = 'OFFLINE'; | |
xhr.send(); | |
} | |
}; | |
</script> | |
</head> | |
<body> | |
Server status: <span id="serverStatus">checking...</span> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment