Skip to content

Instantly share code, notes, and snippets.

@pazguille
Last active August 29, 2015 14:05
Show Gist options
  • Save pazguille/293498a69c6365321a15 to your computer and use it in GitHub Desktop.
Save pazguille/293498a69c6365321a15 to your computer and use it in GitHub Desktop.
function offline() {
document.body.innerHTML = 'You are offline :(';
}
function online() {
document.body.innerHTML = 'You are online :)';
}
window.addEventListener('load', function(e) {
if (navigator.onLine) {
online();
} else {
offline();
}
}, false);
if (window.addEventListener) {
window.addEventListener('offline', offline);
window.addEventListener('online', online);
} else {
document.body.attachEvent('onoffline', offline);
document.body.attachEvent('ononline', online);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment