forked from Nikhil-2002/development_Hactoberfest2025
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeviceInternetStatus.html
More file actions
28 lines (24 loc) · 850 Bytes
/
deviceInternetStatus.html
File metadata and controls
28 lines (24 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<!DOCTYPE html>
<html>
<head>
<title>Check Internet Connection</title>
</head>
<body>
<div id="status">Checking internet connection...</div>
<script>
function checkInternetConnection() {
const statusElement = document.getElementById('status');
const online = window.navigator.onLine;
if (online) {
statusElement.textContent = 'Internet is connected.';
} else {
statusElement.textContent = 'Internet is not connected.';
}
}
// Check the internet connection status initially and then listen for online/offline events.
checkInternetConnection();
window.addEventListener('online', checkInternetConnection);
window.addEventListener('offline', checkInternetConnection);
</script>
</body>
</html>