I am Currently using Tom Riley's Jquery Plugin for Detecting Internet Connection in my Application, It works fine in Internet Explorer, but it does not respond when implementing it in Google Chrome.
Can anybody suggest a better Plugin for Detecting Internet Connection which works perfect in Google Chrome(all Browsers)
You dont need a plugin for that, simply do:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
if (! window.jQuery) {
alert('No internet Connection !!');
}
else {
// internet connected
}
</script>
The reason why above works is because jQuery lib is read from google CDN for which internet connection is required, if page can not read it, it means internet connection isn't there.
You can do something like:
function checkConnection() {
var connected = true;
var img = document.createElement('img');
img.src = "path to remoate image on your server";
img.onerror = function() { connected = false; }
return connected;
}
You can use it like this at any time:
if (checkConnection()) {
// connected
}
You can periodically/automatically check for it too like this:
setInterval(function(){
var isConnected = checkConnection(); // checkConnection() comes from above code
if (isConnected) {
alert('Connected');
}
else {
alert('Not Connected');
}
}, 10000); // 10000 = 10 seconds, check for connection every 10 seconds
Other useful links:
The checkNet plugin ( http://tomriley.net/blog/archives/111 ) works in all browsers, including Chrome. It does not rely on querying google.com (because google is blocked in come countries, and the connection between continents can be unreliable!)
If the error message doesn't show, it's usually because you are still on your local server - it will work when it's on the Internet.
Also, it would be very cool to see what you're using it for. Drop me a link if you feel like sharing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With