---
title: "How to check if internet is connected with browser using JS?"  
description: "How to check if internet is connected with browser using JS?"  
author: "Ravi Vishwakarma"  
published: 2021-07-19  
canonical: https://answers.mindstick.com/qa/93779/how-to-check-if-internet-is-connected-with-browser-using-js  
category: "web application"  
tags: ["javascript", "html", "html5", "css cascading style sheets"]  
reading_time: 1 minute  

---

# How to check if internet is connected with browser using JS?

How to [check if](https://www.mindstick.com/forum/23208/check-if-a-file-exists-using-python) [internet](https://www.mindstick.com/articles/44099/best-internet-hobby) is [connected](https://www.mindstick.com/interview/126/define-connected-and-disconnected-data-access-in-ado-dot-net) with [browser](https://www.mindstick.com/blog/155254/which-is-the-best-internet-browser) using JS?

## Answers

### Answer by Ethan Karla

```
<!DOCTYPE html>
<html lang='en' xmlns='http://www.w3.org/1999/xhtml'>
<head>
    <meta charset='utf-8' />
    <title></title>
</head>
<body>
    <p id='status'></p>
    <script>
        var i = 0;
        setInterval(checkConnection, 1000);
        function checkConnection() {
            if (window.navigator.onLine) {
                document.getElementById('status').innerHTML = 'Connected !!!';
                window.document.body.style.backgroundColor = 'green';
            }
            else {
                document.getElementById('status').innerHTML = 'Disconnected !!!';
                window.document.body.style.backgroundColor = 'red';
            }
        }
    </script>
</body>
</html>
```


---

Original Source: https://answers.mindstick.com/qa/93779/how-to-check-if-internet-is-connected-with-browser-using-js

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
