Created
June 29, 2013 05:57
-
-
Save tofumatt/5890025 to your computer and use it in GitHub Desktop.
Test for network connectivity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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