Skip to content

Instantly share code, notes, and snippets.

@JPustkuchen
Last active Jun 25, 2021
Embed
What would you like to do?
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