Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detect change on navigator.online

How can I detect if the navigator changed your state to online/offline?

something like:

var oldState = navigator.onLine; 
window.navigator.onlinechange = function(evnt,newState) { 
         alert('your changed from' + oldState + ' to' + newState + 'state');
}
like image 312
Jack Avatar asked Aug 11 '11 21:08

Jack


1 Answers

With the help of classes on body and this code you can find

window.ononline = function() {
    alert('You are now online');
}

window.onoffline = function() {
    alert('You are now offline');
}
like image 75
Henrik Albrechtsson Avatar answered Sep 21 '22 02:09

Henrik Albrechtsson