Created
March 4, 2013 01:34
-
-
Save shrwnsan/5079324 to your computer and use it in GitHub Desktop.
Treehouse Web Standard Technology Quick Tip:
Online / Offline Demo As seen at:
http://www.youtube.com/watch?v=8y7O-5TnCUg
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> | |
<head> | |
<title>Online / offline Demo<title> | |
<style> | |
body { background: #6c6; } | |
body.offline { background: #ccc; } | |
.container { | |
width: 500px; | |
background: #fff; | |
border: 1px solid #444; | |
padding: 20px; | |
text-align: center; | |
margin: 100px auto; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<h1>Online / Offline Demo</h1> | |
<h2>This device is currently <span id="status">...</span></h2> | |
</div> | |
<script> | |
function updateStatus() { | |
var textStatus = navigator.onLine ? "online" : "offline"; | |
document.getElementById("status").innerHTML = textStatus; | |
if (navigator.onLine) { | |
document.body.classList.remove("offline"); | |
} else { | |
document.body.classList.add("offline"); | |
} | |
} | |
window.addEventListener("online"), updateStatus); | |
window.addEventListener("offline"), updateStatus); | |
updateStatus; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment