Skip to content

Instantly share code, notes, and snippets.

@cvan
Last active August 29, 2015 13:58
Show Gist options
  • Save cvan/9948621 to your computer and use it in GitHub Desktop.
Save cvan/9948621 to your computer and use it in GitHub Desktop.
using a dummy image to test whether we're online
function checkOnline() {
// `navigator.onLine` is always accurate in Chrome,
// but of course it's *never* accurate in Firefox
// (bug 654579, bug 756364). Yeah, I know - sad times.
return new Promise(function (resolve, reject) {
var i = new Image();
i.src = '/dummy.gif?' + +new Date();
i.onload = function () {
resolve();
};
i.onerror = function () {
reject();
};
});
}
checkOnline().then(function () {
console.log('online');
}, function () {
console.log('offline');
});
4749 4638 3961 0100 0100 8000 0000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment