mirror of
https://github.com/Erreur32/html5demos.git
synced 2024-10-01 15:51:37 +02:00
45 lines
1.3 KiB
HTML
45 lines
1.3 KiB
HTML
<title>on/offline event capture</title>
|
|
<style>
|
|
li {
|
|
font-weight: bold;
|
|
}
|
|
li::before {
|
|
font-weight: normal;
|
|
}
|
|
</style>
|
|
<article>
|
|
<p>Test required here: File -> Work Offline - toggle the value and there <em>should</em> be three list items notifying of online and offline.</p>
|
|
<ul>
|
|
<li>via body "on" events: <span id="viabody"></span></li>
|
|
<li>via window "on" events: <span id="vialistener"></span></li>
|
|
<li>via window.addEventListener: <span id="viaon"></span></li>
|
|
</ul>
|
|
<p>Note that the test shows that <code>window.ononline</code> and <code>window.onoffline</code> doesn't work (which I thought I had read in the specs somewhere...).</p>
|
|
</article>
|
|
<script>
|
|
function update(online) {
|
|
document.getElementById('viabody').innerHTML = navigator.onLine ? 'Online' : 'Offline';
|
|
}
|
|
|
|
addEvent(window, 'online', function () {
|
|
document.getElementById('vialistener').innerHTML = 'Online';
|
|
});
|
|
|
|
addEvent(window, 'offline', function () {
|
|
document.getElementById('vialistener').innerHTML = 'Offline';
|
|
});
|
|
|
|
window.ononline = function () {
|
|
document.getElementById('viaon').innerHTML = 'Online';
|
|
};
|
|
|
|
window.onoffline = function () {
|
|
document.getElementById('viaon').innerHTML = 'Offline';
|
|
};
|
|
|
|
document.body.onOnline = update;
|
|
document.body.onOffline = update;
|
|
|
|
// document.body.onload = update;
|
|
|
|
</script> |