This repository has been archived on 2022-08-19. You can view files and clone it, but cannot push or open issues or pull requests.
hydrogen-web/prototypes/online.html

27 lines
800 B
HTML
Raw Permalink Normal View History

<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<ul id="statuses"></ul>
<script type="text/javascript">
const list = document.getElementById("statuses");
function appendOnlineStatus(onLine) {
const label = onLine ? "device is now online" : "device is now offline";
const txt = document.createTextNode(label);
const li = document.createElement("li");
li.appendChild(txt);
list.appendChild(li);
}
window.addEventListener('offline', () => appendOnlineStatus(false));
window.addEventListener('online', () => appendOnlineStatus(true));
appendOnlineStatus(navigator.onLine);
</script>
</body>
</html>