Created
April 1, 2019 14:45
-
-
Save nekromoff/1a88b07e4145d228dff268672dc8a5f6 to your computer and use it in GitHub Desktop.
This file contains 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
// 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