Skip to content

Instantly share code, notes, and snippets.

@prof3ssorSt3v3
Created March 25, 2020 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prof3ssorSt3v3/2462f0b5442af55913cf8fcd3db60360 to your computer and use it in GitHub Desktop.
Save prof3ssorSt3v3/2462f0b5442af55913cf8fcd3db60360 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>online offline</title>
<style></style>
</head>
<body>
<script>
//get the starting value
let isOnline = 'onLine' in navigator && navigator.onLine;
window.addEventListener(
'online',
function online() {
document.body.classList.add('hidden');
isOnline = true;
},
false
);
window.addEventListener(
'offline',
function offline() {
document.body.classList.remove('hidden');
isOnline = false;
},
false
);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment