Verify that the user is connected to the internet

-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 there is no file, only the config.xml pointing to the site, when installing the plugin, I can not call because the app has nothing, all the files are on the server, can I install the plugin on the server?

    
asked by anonymous 01.05.2018 / 05:23

1 answer

1

You can check the link using the navigator.onLine

Example taken from the MDN Web Docs website

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

Another example through event listeners that allows you to manipulate the connection state as the changes:

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

window.addEventListener('online', function(e) { console.log('online'); });
    
02.05.2018 / 20:05