Detect offline online using JavaScript

Detect offline online using JavaScript

If you want to detect offline or online status of your client using JavaScript then this article will help you in that case.

You can detect whether your client is offline or online using a single line of JavaScript code. To simply detect the offline or online status of your client you can use the following JavaScript code.

if (navigator.onLine != true) {
    return false;
} else {
    return true;
}

This is basically a conditional statement that will check the status. If your client is online then the script will return true else it will return false.

To make this easy to understand I have an example for you. You can copy this code and view its output. You will see that if you are online then you will see a green color scheme otherwise you will see a red color scheme.

Just simply go to this page and see the demo and if you want the source code you can also copy that from this demo page.

Click To View Demo

Related Posts

M.Muzammil

I am a web Designer & Graphics Designer. I love to program and design. Sharing knowledge is my passion & Programming is my Hobby. Want Help? Contact Me its free.!

Be The First To Comment

Add Comment