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.
Update
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
}
Update 2
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:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…