View Full Version : Online Status
tomalex0
15 Jul 2010, 11:20 PM
I have doubt regarding getting online/offline status,if internet is connected or not?
I have tried (navigator.onLine) but its not working in webkit browsers, is there any alternative in sencha
or do i have to send some http request and get the status?
tomalex0
20 Jul 2010, 9:15 AM
Solved
Hi the problem exists in chrome and safari browser, it works fine in iphone and ipad
gabrielstuff
28 Sep 2010, 6:10 PM
Hi !
I've been trying to use the state navigator.online sothat I would be able to check if I need to wait for a read event on jsonstore load.
Unfortunately... It does not work :(
Did you try or manage to do so ?
Thanks !
tomalex0
28 Sep 2010, 8:25 PM
I have tried (navigator.onLine) in Chrome and Safari in offline mode , but it shows true as status. Probably its not working.
evant
28 Sep 2010, 8:45 PM
http://code.google.com/p/chromium/issues/detail?id=7469
gabrielstuff
3 Oct 2010, 4:38 PM
Ok ! Thank you evant. I made a dirty trick :
var tempImage;
onlineStatus = true;
function checkOnlineStatus() {
tempImage = new Image();
tempImage.onload = returnOnlineStatus;
tempImage.onerror = returnOfflineStatus;
var imgSrc = 'http://www.google.fr/images/logos/ps_logo2.png'; // point to the url of a valid image.
tempImage.src = imgSrc;
return !(tempImage.width == 0 && tempImage.height == 0);
}
function returnOnlineStatus() {
if (tempImage.width == 0 && tempImage.height == 0) {
onlineStatus = false;
} else {
onlineStatus = true;
}
}
checkOnlineStatus();
kortovos
14 Jul 2011, 12:28 AM
I have found a similar solution. It alters the navigator.onLine attribute, but it doesn't work with Safari
var onLine = false;
// make sync-ajax request
var xhr = new XMLHttpRequest();
xhr.open('GET', 'url to not cached file', false); // async = false
try {
xhr.send();
console.log(xhr.status);
if(xhr.status != 404){
onLine = true;
}
} catch (e) {
// throws NETWORK_ERR when disconnected
onLine = false;
}
if(onLine){
navigator.__defineGetter__('onLine', function () {
return true;
});
}else{
navigator.__defineGetter__('onLine', function () {
return false;
});
}
delete onLine;
delete xhr;
window.addEventListener("offline", function(){
console.log('offline');
navigator.__defineGetter__('onLine', function () {
return false;
});
}, false);
window.addEventListener("online", function(){
console.log('online');
navigator.__defineGetter__('onLine', function () {
return true;
});
}, false);
Powered by vBulletin® Version 4.1.5 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.