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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With