Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Tip to detect Online/Offline Mode

0.00/5 (No votes)
1 Oct 2014 1  
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. :)

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here