Thursday 6 July 2017

How to check internet connection using javascript

Here is the simple javascript function for getting internet status working or not..

<script>
function checkInternetCon() {
var status = navigator.onLine;
if (status) {
alert("Yes!! Working");
} else {
alert("Sad!! Not Working ");
}
}</script>
 
 
 
 
Call above function on button onclick event.
 
 
<button onclick="checkInternetCon()">Check Internet Connection</button>
 
 
You can also use setInterval method in javascript
 
 
setInterval(function(){ 
var status = navigator.onLine;
 if (status) {
 console.log('Working..');
 } else {
  console.log('Not Working..');
 }
}, 5000); 
 
  

No comments:

Post a Comment