Skip to content

Check whether browser is online using JavaScript

The onLine property under navigator object returns the online status of the browser. We can use this property to check if the browser is online.

if (navigator.onLine) 
  console.log('You are online');
  console.log('You are offline');

//You are online

Attach this to an event listener you can enable notifications or call functions when browser goes online / offline.

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

window.addEventListener('offline', function(e) {
    console.log('You are offline');
See also  Electronics Shop - Hackerrank Challenge - C# Solution

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.