Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome OS, quickly tell if there is an internet connection or not via a Chrome extension?

I am trying to write an extension that will cache page content for offline reading. If the user activates the extension's popup while offline, I would like to show the cached content. Currently, I am thinking I can make an ajax request and wait to see if it fails, but if there is a part of the chrome API that would let me do this more quickly, that would be ideal.

I have done some googling and haven't come across anything.

like image 468
Chris Sobolewski Avatar asked Feb 27 '12 21:02

Chris Sobolewski


1 Answers

if (navigator.onLine) {
  // Online
} else {
  // Offline
}

It also supports event listeners.

https://developer.mozilla.org/en/Online_and_offline_events

like image 75
abraham Avatar answered Sep 22 '22 10:09

abraham