Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch flaky Internet connections

Tags:

javascript

I have a situation where the user has a Wi-Fi connection, but the Wi-Fi is not connected to the Internet.

So navigator.onLine produces a true, but in reality the user is not online. Short of doing an actual ajax call, is there another indicator to tell whether we’re online or not?

I seem to remember that PhoneGap had an extra indicator.

like image 778
SwatchDog Avatar asked Feb 15 '23 15:02

SwatchDog


1 Answers

Something like this should work

var req = new XMLHttpRequest();
req.open('GET', 'http://www.google.com', false);
req.send(null);
if(req.status == 200)
   alert(req.responseText);
like image 102
user123_456 Avatar answered Mar 05 '23 16:03

user123_456