Online connectivity check using plain javascript

  1. Open google developer tools Console (Ctrl+Shift+I).
  2. Click Toggle device bar or do Click Ctrl+Shift+M. You can see the mobile view here.
  3. At the top of this view, we will have option to select device, adjust size and then there is a drop down where you can switch between online and offline. Check the below screenshots.
Offline- Console message is “The network connection has been lost”
Online- console message is “The network connection is back”

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store