Skip to content

Instantly share code, notes, and snippets.

@tadman
Created January 27, 2015 21:23
Show Gist options
  • Save tadman/db658360cc0feb903d38 to your computer and use it in GitHub Desktop.
Save tadman/db658360cc0feb903d38 to your computer and use it in GitHub Desktop.
Automatic Page Refresher
var refresh_element = $('#refresh')[0];
if (refresh_element) {
$(refresh_element).data('refresh', 1);
setInterval(function() {
if ($(refresh_element).data('refresh'))
$(refresh_element).load(window.location.href + ' #refresh');
}, 5000);
var pauseRefreshments = function() {
if ($(refresh_element).data('refresh')) {
$('#pause').html('Resume');
$(refresh_element).data('refresh', 0);
}
else {
$(refresh_element).data('refresh', 1);
$('#pause').html('Pause');
}
};
$('#pause').live('click', function(ev) {
ev.preventDefault();
pauseRefreshments();
});
$('body').keyup(function(e) {
var p_key = 80;
if (e.which === p_key) {
pauseRefreshments();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment