Created
March 25, 2020 19:48
-
-
Save prof3ssorSt3v3/2462f0b5442af55913cf8fcd3db60360 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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