Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript to check the status of wireless connection

Tags:

javascript

I have developed an application and it works great over the Ethernet connection, but now I am running my application over a wireless network and I see that the wireless connection sometimes disconnects.

I want to check the status of the wireless connection using javascript so that I can show a meaningful error message on my screen.

Is there any way I can achieve this using plain javascript code, without relying on a framework like jQuery?

like image 812
Java Hunger Avatar asked Aug 12 '13 16:08

Java Hunger


People also ask

How do you recognize status of wireless?

Select the Start button, then type settings. Select Settings > Network & internet. The status of your network connection will appear at the top. Windows 10 lets you quickly check your network connection status.

How do I know if I have no Internet connection?

You can use a site like downdetector.com to see if anyone else is having connection issues in your area. Many ISPs also have outage alerts via their websites and apps. Of course, you could always just contact your ISP to find out if there's an outage.

How do I know if I have JavaScript Internet?

JavaScript has a function called navigator. This browser property can be used to determine if you are connected to the internet. It returns true or false depending on the status of the client's network and says whether the browser is online or offline easily.


1 Answers

Browser errors and system tray icons will sufficiently indicate the state of the wireless network to the user.

The way you describe your application indicates, to me, that you are doing some kind of continuous AJAX-style querying that is frequently interrupted. Rather than concentrating on underlying network connections, I recommend taking a more business-level approach: If your application cannot maintain a connection (or does not receive a response within a certain time limit), simply notify the user that a connection could not be established (for added robustness, keep retrying until it succeeds -- see, e.g. GMail's web interface). The user will have other means to diagnose why - your application should not and can not know the reason for the failure, your application only knows that it needs to connect to the server and can't. (As a bonus, handling errors in this way could give you the basis for a framework for handling other server-side errors as well, e.g. displaying a message if data services are down for maintenance, etc.)

If you are loading all data when the page is loaded, rather than querying through scripts after load, then the user's browser will display an error indicating that the page could not be loaded, and you do not need to provide that.

like image 165
Jason C Avatar answered Sep 21 '22 05:09

Jason C