HTML5 · Javascript · Professional

Detecting online/offline status

Detecting whether the browser is online or not.
navigator.onLine is working fine in Mozilla Firefox and Opera
Using the code

var onlineOfflineStatus=navigator.onLine ? ‘online’ : ‘offline’;
alert(onlineOfflineStatus);

But this code not work in Chrome
Use ajax jquery

var connectSuccess = 0;
$.ajax({
type: “POST”,
url: ‘onlineOfflineTested.php’,
cache: false,
dataType: “html”,
success: function(data){
connectSuccess = 1;
},
error:function (xhr, ajaxOptions, thrownError){
connectSuccess = 0;
}
});
if(connectSuccess == 1) {
alert(‘Online’);
} else {
alert(‘Offline’);
}

url: onlineOfflineTested.php,onlineOfflineTested.cfm etc.
simple page with out any codding.

Advertisements

2 thoughts on “Detecting online/offline status

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s