forked from mr-body/bookstoreHTML
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinternet.html
More file actions
36 lines (33 loc) · 1.22 KB
/
internet.html
File metadata and controls
36 lines (33 loc) · 1.22 KB
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
29
30
31
32
33
34
35
36
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Teste de Conexão à Internet</title>
</head>
<body>
<h1>Teste de Conexão à Internet</h1>
<p id="status"></p>
<script>
// Verificar a conexão à Internet
function checkInternetConnection() {
fetch('https://www.google.com', { mode: 'no-cors' })
.then(function(response) {
if (response.ok || response.type === 'opaque') {
document.getElementById('status').innerText = 'Você está conectado à Internet.';
} else {
document.getElementById('status').innerText = 'Você está offline. Por favor, verifique sua conexão.';
}
})
.catch(function(error) {
document.getElementById('status').innerText = 'Erro ao verificar a conexão.';
});
}
// Verificar a conexão à Internet quando a página é carregada
window.onload = checkInternetConnection;
// Verificar a conexão à Internet quando há uma alteração na conexão
window.addEventListener('online', checkInternetConnection);
window.addEventListener('offline', checkInternetConnection);
</script>
</body>
</html>