In article <3s************@individual.net>,
Peter Flynn <pe********@m.silmaril.ie> wrote:
Ivan Marsh wrote:
On Thu, 27 Oct 2005 22:38:47 +0100, Peter Flynn wrote:
I'm having trouble finding example code to detect the presence of an
Internet connection. It doesn't seem to be a very frequently asked
question, as all I need is the answer yes or no (is the user connected
or not). I'm not interested in speed detection or any other aspect of
the connection, just its existence or not. The reason is to be able to
intercept link clicks on a CD-based set of HTML pages and pop up a
warning if there is no connection; otherwise pass the request through to
the net.
How would you intend to determine between having an IP address on a LAN
and having a connection on to the internet without pinging an address on
the internet?
For the specific application the users involved either have Internet
access or they are offline completely (eg using a laptop out of range
of wireless, phone, etc), so the state of being on the LAN but without
Internet access won't arise (fortunately).
The easiest way is to ask the user: Do you have a connection to the
internet?
The publisher is against this...
///Peter
In that case a fairly quiet way to go about this might be to do an
XMLHttpRequest for something -- anything, really -- in the background.
If it returns meaningful data, you can conclude they have a connection.
If it doesn't, you can conclude that they either don't or that something
is wrong at the other end. In either case, if you are dealing with just
the client's servers, you know you are down, though you might want to
phrase the user info carefully, i.e.: Your internet connection is not
active or there is an issue with the server. Please contact such and
such if you feel this message is in error...