Skip to content

Instantly share code, notes, and snippets.

@lusbuab
Created December 2, 2019 21:17
Show Gist options
  • Save lusbuab/e6c87aa1f6a97121ce8ec9e8c8bcd8b1 to your computer and use it in GitHub Desktop.
Save lusbuab/e6c87aa1f6a97121ce8ec9e8c8bcd8b1 to your computer and use it in GitHub Desktop.
Refresh the page if it was inactive for too long.
;(function(refreshAfter){
var hideTime = null
document.addEventListener("visibilitychange", function() {
if (document.hidden) {
hideTime = Date.now()
} else if (hideTime && Date.now() - hideTime > refreshAfter) {
location.reload()
}
}, false)
}(5000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment