HTML and CSS Reference
In-Depth Information
line is about halfway down, where req.responseText is checked to see if
it contains the string 'OFFLINE' :
function check_online(online_fn, offline_fn) {
var currentTime = new Date()
req = window.XMLHttpRequest ?
new XMLHttpRequest() :
new ActiveXObject("MSXML2.XMLHTTP.3.0");
var freshUrl = 'online.txt?brk=' + currentTime.getTime();"GET", freshUrl, true);
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200) {
if (req.responseText.indexOf('OFFLINE') > -1) {
} else {
} else {
Having your application available when there's no connectivity is one
thing, but most applications need to interact with data to be useful.
If all the data is on the server, then having the application work
offline isn't of much use in itself. In the next section, you'll learn
about storing data so it's available for offline applications.
Storing data for offline use
In this section, you'll learn about the Web Storage API , a convenient
way to store data in the browser. Although web storage is crucial for
any sort of offline application, it's also useful for providing quick access
to data in the browser without having to repeatedly request it from the
server. Web storage comes in two flavors: local storage, which is persis-
tent across browser sessions, and session storage, which is lost when
the user ends their browsing session. The storage API s are also avail-
able to offline apps, making them extremely useful for caching your
Search WWH ::

Custom Search