Detecting the current state of the network connection and responding to any changes that might occur, can be done by using one of several plugins. This example is about the cordova-plugin-network-information plugin.
Add the plugin to the project:
cordova plugin add cordova-plugin-network-informati...