IDENTIFY WHETHER THE NETWORK IS ONLINE
For this to happen, you need to listen for the existing online and offline events. When the browser is online, test the network. When it is offline, the network is lost:
addEventListener('online', testNetwork, false); addEventListener('offline', lostNetwork, false); function testNetwork() ...