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.
1 Answer
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.');
}
});
-
1Good logic, but are you sure the page does not return a HTTP error message instead of page...– StarxCommented 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."– JakeCommented Jan 11, 2011 at 10:02