Q:

Check the internet connection for each and every time of submission in JavaScript

Is there any possible way to check the internet connection for each and every time of submission in JavaScript?

A:

You can use navigator.onLine to check the either there is internet connection or not. You can also use 2 event listener to notify when network connection is connected or disconnected.

console.log(navigator.onLine);

// OR

window.addEventListener('online', () => {
   //console.log('Online');
});

window.addEventListener('offline', () => {
        //console.log('Offline');  
});

