Check Internet connectivity with jquery

前端 未结 7 785
无人及你
无人及你 2020-12-05 20:29

I am trying to check for the internet connection by sending a GET request to the server. I am a beginner in jquery and javascript. I am not using navigator.onLine

7条回答
  •  鱼传尺愫
    2020-12-05 21:04

    This piece of code will continue monitoring internet connection click bellow "Run code snippet" button and see it in action.

    function checkInternetConnection(){
            var status = navigator.onLine;
            if (status) {
                console.log('Internet Available !!');
            } else {
                console.log('No internet Available !!');
            }  
            setTimeout(function() {
                checkInternetConnection();
            }, 1000);
          }
    
    //calling above function
    checkInternetConnection();

提交回复
热议问题