local storage and session storage

Viewed 22928

I'm taking my first step of a thousand miles with the new local storage and session storage found in html5.

http://www.w3.org/TR/offline-webapps/

Q: Is there a code example of using either session storage or local storage, where the user enters a value, the value is saved locally, the user then connects to the Internet on his 56K modem and the local storage is synced with a server?

3 Answers

Instead of using the setInterval and blindly trying to send data to your server, check the navigator.onLine property:

if (navigator.onLine) {
   // Send data using XMLHttpRequest
} else {
   // Queue data locally to send later
}

You can also add listeners to the Window object for the "online" and "offline" events which will let you know when the browser has internet connectivity again.

Related