JavaScript Detecting Internet Connection


Hits: 396  

Offline.js automatically alerts users for their internet connection using AJAX requests.

Download offline.min.js

offline.html

<script src="offline.min.js"></script>
<script>

Offline.options = {checks: {xhr: {url: 'offline.html'}}};

var run = function(){

// check internet connection
Offline.check();

// return internet connection state  
console.log(Offline.state);

document.getElementById("status").innerHTML = Offline.state; 
 
}

setInterval(run, 5000);

</script>

<div id="status">up</div>

Published by

Sandeep Verma

I’m an Entrepreneur. I’m proud to work as Blogger, LAMP Programmer, Linux Admin, Web Consultant, Cloud Manager, Apps Developer, Searcher. Concentrate > Observe > Imagine > Launch