0

I was wondering how I could run js if the user goes offline during the time that they are on my site.

What I'm planning on doing is notifying them so they know and can reconnect?

I was using offline.js, here: http://github.hubspot.com/offline/docs/welcome/, but that is too complex for what i'm building honestly.

gomangomango
  • 661
  • 1
  • 10
  • 29

1 Answers1

4

Listen for offline events on window:

window.addEventListener('offline', offlineHandler);

or if you want it more jQueryish,

$(document).on('offline', offlineHandler);
Amadan
  • 191,408
  • 23
  • 240
  • 301
  • Cool! What's the compatibility like? Is there an `online` event too? – Scott Rippey Apr 01 '14 at 06:00
  • 1
    @ScottRippey: Indeed there is, as can be found on the linked page. As for compatibility... [Sigh.](http://stackoverflow.com/a/9677537/240443) – Amadan Apr 01 '14 at 06:38