Created
October 15, 2015 09:59
-
-
Save anonymous/11dcaecc7e7f24048547 to your computer and use it in GitHub Desktop.
Offline/Online event toggling demo // source https://jsbin.com/liyeyuluru
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
<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