Skip to content

Instantly share code, notes, and snippets.

@JPustkuchen
Last active June 25, 2021 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JPustkuchen/1e75ae0ec79ef2dc76d3d8d41feb7fd7 to your computer and use it in GitHub Desktop.
Save JPustkuchen/1e75ae0ec79ef2dc76d3d8d41feb7fd7 to your computer and use it in GitHub Desktop.
JavaScript jQuery Page Auto Reload Timer with enable / disable checkbox
<script>
$( document ).ready(function() {
window.setInterval(function() {
if($('#autoreload').is(':checked')){
if(('#autoreload-wrapper .countdown').length && (parseInt($('#autoreload-wrapper .countdown').text()) <= 1)){
// Reload every 60 seconds without sending POST again:
window.location.href = window.location.href;
} else {
$('#autoreload-wrapper .countdown').text(parseInt($('#autoreload-wrapper .countdown').text()) - 1);
}
}
}, 1000);
});
</script>
<style>
#autoreload-wrapper {
display:block;
position:fixed;
bottom:0;
left:0;
background-color:#fff;
border: 1px #EEE solid;
z-index: 99999;
padding: 6px;
}
</style>
<div id="autoreload-wrapper">
<input type="checkbox" value="1" id="autoreload" checked="checked">
<label for="autoreload">Autom. neu laden (<span class="countdown">60</span>s)</label>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment