Tip to detect Online/Offline Mode






4.60/5 (12 votes)
How to detect Online/Offline mode through code
Introduction
In today's development world, we are creating web applications which can run in both modes (i.e. online and offline mode) using HTML5 capabilities.
Below is the sample code to detect current mode using JavaScript:
<script>
window.addEventListener('load', function (e) {
}, false);
window.addEventListener('online', function (e) {
alert("you are online"); //alert for online status
}, false);
window.addEventListener('offline', function (e) {
alert("you are offline");//alert for offline status
}, false);
</script>
Use the above code and play with online /offline mode. :)