Code:
<script type="text/javascript">
function checkConnection(yesfunc, nofunc) {
var e = document.createElement("img");
e.onerror = function() {
nofunc();
e = null;
};
e.onload = function() {
yesfunc();
e = null;
};
e.src = "http://www.google.com/images/google_sm.gif?c=" + (new Date().getTime());
}
checkConnection(
function() {
alert("Internet connection succeeded.");
},
function() {
alert("Internet connection failed.");
}
);
</script>
This is more reliable than AJAX: there are less reasons it could give a false negative (although there are still some).
Bookmarks