// stub for the offline application in pseudocode // from http://ejohn.org/blog/offline-events/ function saveData( item ){ if ( navigator.onLine ) { saveToServer( item ); } else { toSave.push( item ); } } function loadData( item ){ if ( navigator.onLine ) { return loadFromServer( item ); } else { var result = loadFromQueue( item ); if ( !result ) { displayError(); toLoad.push( item ); } return result; } } setInterval(function(){ if ( navigator.onLine ) { var item = predictNextItemToBeLoaded(); loadData( item ); } }, 5000); window.ononline = function(){ toSave.forEach( saveData ); toLoad.forEach( loadData ); }; window.onload = function(){ document.getElementById("myform").onsubmit = function(){ saveData( this ); return false; }; };