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;
    }


}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.