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.
Asked
Active
Viewed 3,599 times
1 Answers
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.');
}
});

Jake
- 12,713
- 18
- 66
- 96
-
1Good logic, but are you sure the page does not return a HTTP error message instead of page... – Starx Jan 11 '11 at 09: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 Jan 11 '11 at 10:02