lautarobock / brew-o-matic-III

Nueva version del emocionante software cervecero
MIT License
0 stars 0 forks source link

Detectar ofline/online #4

Open lautarobock opened 8 years ago

lautarobock commented 8 years ago

Detecting if you're online

There's an HTML5 API to let you query if a browser is online: navigator.onLine(). It works on recent IE, Firefox, Opera, and Chrome. You can also listen for these online/offline events using document.body.addEventListener("online", function () {...} and document.body.addEventListener("offline", function () {...}.

You should generally assume the network is present and make calls as normal. It's only in the event of a server timeout or related error that you should invoke navigator.onLine. Doing so will serve two purposes: (a) you can decide if the error is caused by a network outage versus a server-specific outage, and if it's a network outage, inform the user so they can get back online; (b) you can start watching for the "online" event, and take action when the user's back online.