0

Obviously this is a Javascript problem. As javascript are already loaded to the server, I was wondering if there is way to check whether there is active internet connection or not.

0

1 Answer 1

2

You could send an ajax request and see if it gets a response.
With jQuery:

$.ajax({
  url: 'ajax/test.html',
  success: function(data) {
    alert('Connection.');
  },
  error: function(data) {
    alert('No Connection.');
  }
});
2
  • 1
    Good logic, but are you sure the page does not return a HTTP error message instead of page...
    – Starx
    Commented Jan 11, 2011 at 9:55
  • Yes, you have to be sure the test page does not return a HTTP error. It's probably a good idea to display an error like "Can't connect to example.com server" rather than "You have no internet connection."
    – Jake
    Commented Jan 11, 2011 at 10:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.