Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nekromoff/1a88b07e4145d228dff268672dc8a5f6 to your computer and use it in GitHub Desktop.
Save nekromoff/1a88b07e4145d228dff268672dc8a5f6 to your computer and use it in GitHub Desktop.
// browser kiosk web app refresh via Javascript
// this test if network is up and browser is online
function refresh() {
// network is up (but this does not mean there is a live internet connection)
if (navigator.onLine == true) {
$.ajax({
// try to fetch non-existent 404 URL that is not cached (include timestamp)
url: '../X24S54d4wqewq887_madeup_url_online_test' + new Date().getTime(),
// timeout after 3 seconds
timeout: 3000,
// always error, but
error: function(xhr) {
console.log(xhr.status)
// 404 actually means we have received live connection status back from server !
if (xhr.status == 404) {
window.location.reload(true);
} else {
// no response from server, let's retry in 6 seconds
setTimeout(refresh, 6000);
// failed to reload
}
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment