Skip to content

Instantly share code, notes, and snippets.

@carlessanagustin
Last active August 27, 2018 14:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlessanagustin/a4a8b748186281a3d1fe to your computer and use it in GitHub Desktop.
Save carlessanagustin/a4a8b748186281a3d1fe to your computer and use it in GitHub Desktop.
(Javascript) Auto refresh checkbox
<!-- add Javascript in html head -->
<script>
var reloading;
var refresh_time = 30000;
function checkReloading() {
if (window.location.hash=="#autoreload") {
reloading=setTimeout("window.location.reload();", refresh_time);
document.getElementById("reloadCB").checked=true;
}
}
function toggleAutoRefresh(cb) {
if (cb.checked) {
window.location.replace("#autoreload");
reloading=setTimeout("window.location.reload();", refresh_time);
} else {
window.location.replace("#");
clearTimeout(reloading);
}
}
window.onload=checkReloading;
</script>
<!-- add input checkbox in html body -->
<span><input type="checkbox" onclick="toggleAutoRefresh(this);" id="reloadCB"> Auto Refresh</span>
@wytcld
Copy link

wytcld commented Aug 27, 2018

This no longer works in Chrome or Firefox. Still works in IE. Used to work in all three.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment