HTML5 – CHECK IF YOU ARE ONLINE OR OFFLINE – OFFLINE APPS BASICS

Hi. I am building now offline app integrated with remote server database. I was looking for some kind of way to send data to remote database automatically when user is online without user action as he can be busy or maybe lazy and just forgot to do that. Found cool way via JavaScript. It is easy and good ! Drop code placed below and turn your internet connection on and off to see how it works !
window.addEventListener("online", function() {
 console.log('You are ONLINE');
        alert("You are ONLINE now. So I've made all updates now ...");
        // dataUpdatingFunctionHere();
}, true);

window.addEventListener("offline", function() {
 console.log('You are OFFLINE');
        alert("You are OFFLINE now. So I will write all changes to HTML5 Local Storage ! WOW !");
        // savingDataLocallyFunctionHere();
}, true);