Reputation: 81
I am using offline js for internet detecting up and down. My code is below
$(document).ready(function () {
Offline.options = {
reconnect: {
initialDelay: 10,
delay: (5)
}
}
Offline.on('up', internetUp);
Offline.on('down', internetDown);
function internetUp(event, data) {
console.log("Internet is up.");
}
function internetDown(event, data) {
console.log("Internet is down.");
}
});
I am facing the problem When internet is down there is no event fire and when internet is up both events are fired need help i am using offline-js 0.7.13 version.
Upvotes: 0
Views: 190
Reputation: 6265
Check to see if it works without a 3rd party module.
You can check the browser's navigator.onLine
value
https://developer.mozilla.org/en-US/docs/Web/API/NavigatorOnLine/onLine
In the above code, in your ready function you can attach an eventHandler to the window that detects online / offline events
window.addEventListener('online', updateOnlineStatus);
window.addEventListener('offline', updateOnlineStatus);
https://developer.mozilla.org/en-US/docs/Online_and_offline_events
Upvotes: 1