Skip to content

Instantly share code, notes, and snippets.

@tofumatt
Created June 29, 2013 05:57
Show Gist options
  • Save tofumatt/5890025 to your computer and use it in GitHub Desktop.
Save tofumatt/5890025 to your computer and use it in GitHub Desktop.
Test for network connectivity
// We'll assume we aren't online.
var online = false;
// Assume we're a packaged app with systemXHR permissions.
// See: https://developer.mozilla.org/en-US/docs/Web/Apps/App_permissions for more.
var request = new window.XMLHttpRequest({mozSystem: true});
request.open('GET', 'http://mozilla.com', true);
request.addEventListener('load', function(event) {
console.log('We seem to be online!', event);
online = true;
});
request.addEventListener('error', function(event) {
console.log('We are likely offline:', event);
});
request.send(null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment