Javascript to check the status of wireless connection


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?

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.


you could use coffee script. you don't need jQuery to use it. This will only warn your users when their network goes down.