Checking if the browser is online

There is a easy way to check if the browser as internet access or not. In the wireless and mobile world a check if the loaded page has internet access can be very good, a very easy check can save you alot of problem.

The only thing you need to do is

if(navigator.onLine==true){
alert("Online")
}else{
alert("Offline")
}

  1. To be clear, does this mean that the browser is in offline mode or does it mean that has a valid internet connection?

    Could be useful thanks 🙂

    • Fredrik Norling

      I have checked it by loading up a page and removing the wireless connection. And yes it will detect this so it’s not only offline mode in the webbrowser that is detected.

  2. Tense version:

    alert(navigator.onLine ? “Online” : “Offline);

    you don’t actually need a == true since it is boolean already;

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

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