Skip to content

Instantly share code, notes, and snippets.

@zspitzer
Forked from anonymous/index.html
Created October 15, 2015 10:00
Show Gist options
  • Save zspitzer/4058c61551c513d8a4b8 to your computer and use it in GitHub Desktop.
Save zspitzer/4058c61551c513d8a4b8 to your computer and use it in GitHub Desktop.
Offline/Online event toggling demo // source https://jsbin.com/liyeyuluru
<html>
<head>
<title>Offline/Online event toggling demo</title>
<script>
var online = function () {
logger("<B>online</B>");
}
var offline = function () {
logger("offline");
}
var logger = function (status){
var log = document.getElementById('log');
console.log(status);
log.innerHTML += "<br>" + status + " :: navigator.onLine:" + navigator.onLine + " :: " + new Date();
}
window.addEventListener('online', online);
window.addEventListener('offline', offline);
console.log('listening for online/offline effects');
</script>
</head>
<h1>listening for online/offline effects</h1>
<input type="button" value="poll network status" onclick="javascript:logger('<i>checking status</i>');">
<div id="log">
</div>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment