470,826 Members | 1,898 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,826 developers. It's quick & easy.

Detecting presence of Internet connection

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.

///Peter

Oct 27 '05 #1
4 2592
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?

The easiest way is to ask the user: Do you have a connection to the
internet?

--
The U.S. Government today announced that it is changing its emblem from an
Eagle to a CONDOM because it more accurately reflects the government's
political stance... A condom allows for inflation, halts production, destroys
the next generation, protects a bunch of pricks, and gives you a sense of
security while you're being screwed.

Oct 27 '05 #2
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
Oct 27 '05 #3
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.

///Peter


I think your real requirement is to detect if a particular resource is
avaialble or not - whether the user has access to the internet or not
is moot. Access to the URI could be blocked for any number of reasons
unrelated to general internet access. Resources may be in different
domains; some local, others not.

There are detailed instruction at the link below, with code, to detect
whether the user can access a particular URI. Create a 'can my
function access this URI' function based on the code provided and you
will have a much more robust function that doesn't care about how or
whether the user is connected to internet:

<URL:http://www.xml.com/pub/a/2005/02/09/xml-http-request.html>
--
Rob

Oct 28 '05 #4
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...
Oct 28 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Matt Hawley | last post: by
3 posts views Thread by Jonny | last post: by
reply views Thread by Woo Mun Foong | last post: by
6 posts views Thread by =?Utf-8?B?QnNtZW5nZW4=?= | last post: by
1 post views Thread by =?Utf-8?B?QiBTaW5naA==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.