Javascript to check wireless status

I developed the application and it works great on the Ethernet connection, but now I run my application over the wireless network and I see that the wireless connection is sometimes disconnected.

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

Is there a way to achieve this using simple javascript code without relying on a framework like jQuery?

+6
source share
2 answers

Browser errors and system tray icons will be enough to indicate the status of the wireless network for the user.

The way you describe your application indicates that you are making some kind of continuous AJAX style request, which is often interrupted. Instead of concentrating on basic network connections, I recommend using a more business approach: if your application cannot support the connection (or does not receive a response within a certain period of time), simply inform the user that the connection cannot be established (to increase reliability keep trying again until it succeeds - see, for example, the GMail web interface). The user will have other diagnostic methods, why - your application should not and cannot know the reason for the failure, your application knows that it needs to connect to the server and cannot. (As a bonus, error handling in this way can give you the basis for processing other errors on the server side, for example, displaying a message if data services are not available for maintenance, etc.)

If you download all the data when the page loads, rather than requesting it through scripts after loading, then an error message is displayed in the user's browser indicating that the page cannot be loaded, and you do not need to provide it.

+5
source

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

0
source

Source: https://habr.com/ru/post/951567/


All Articles