Start New Discussion within our Web Development Community

Hello. I have a function that checks the internet connection. I need to set a timeout to it. I have tried without success to do that. Please help. Here is the function:

function isOnline() {
    if(navigator.onLine){
        var uri = baseUrl+'ping';
        var xhr = new XMLHttpRequest();
        xhr.open('GET',uri,false);
        try{
            xhr.send();
            return true;
        }catch(err){
            return false;
        }
    }else{
        return false;
    }


}
This article has been dead for over six months. Start a new discussion instead.