How to alert users when connection is disconnected using Offline.js feature

I am trying to alert users when they are offline and will show a simple message. I am using offline .js as a library ( Offline.js website ).

I want to write JS and not use Eager to install it automatically.

Here is what I wrote, but it doesn't seem to work. Can anyone help me with more details?

I could not find a sample with code on the library website.

Offline.options = {checkOnLoad: true, checks: {image: {url: 'http://www.vitaminedz.com/photos/49/02-49565-front-de-mer-a-oran.jpg'}, active: 'image'}}

Offline.check();
Offline.on('up', alert('up'));
Offline.on('down',alert('down'));

      

JSFiddle Code + DEMO

+3


source to share


2 answers


Your handlers are not configured correctly. It should be like this:



alert(Offline.check());
Offline.on('up', function() {
    alert('up');
});
Offline.on('down', function() {
    alert('down')
});

      

+5


source


After linking theme js and css offline, you add this code.

<script type="text/">
var run = function(){
if (Offline.state === 'up')
Offline.check();
}
 setInterval(run, 1000);
</script>

      



NOTE. It will only work if you call your jquery.js code above it.

0


source







All Articles