-
-
Save zspitzer/4058c61551c513d8a4b8 to your computer and use it in GitHub Desktop.
Offline/Online event toggling demo // source https://jsbin.com/liyeyuluru
This file contains hidden or 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
<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