Check if the user is connected to the internet

Asked

Viewed 1,176 times

-1

I need to know if the user is connected to the internet, and if not, I need to show a screen, but my case is that I created an app from a responsive site that I have, in my app has no file, only the config.xml pointing to the site, when installing the plugin, I have no way to call because the app has nothing, all the files are on the server, it is possible to install the plugin on the server?

  • Edmilson, improve your question, because it is not detailed.

1 answer

1

You can check the connection via the command Navigator.

Example taken from MDN Web Docs website

if (navigator.onLine) {
  console.log('online');
} else {
  console.log('offline');
}

Another example via Event listeners allows you to manipulate the connection status as you change:

window.addEventListener('offline', function(e) { console.log('offline'); });

window.addEventListener('online', function(e) { console.log('online'); });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.