Looks like you are talking of Internet Connection. If so:
You can determine that the connection is lost by making
failed XHR requests.
The standard approach is to retry the request a few times. If it doesn't go through, alert the user to check the connection, and fail gracefully.
For XMLHttpRequest, read here:
XMLHttpRequest Object[
^]