Skip to content

Instantly share code, notes, and snippets.

@thisisnic
Last active December 17, 2022 12:11
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thisisnic/4c0606f14b62e1aa2e3de02abbbe7af4 to your computer and use it in GitHub Desktop.
Save thisisnic/4c0606f14b62e1aa2e3de02abbbe7af4 to your computer and use it in GitHub Desktop.
Confirm "back" browser button click in Shiny
history.pushState(null, null, null);
window.addEventListener('popstate', function () {
const endProgress = confirm('This will end your session, are you sure you want to go back?');
if (endProgress) {
window.onpopstate = null;
history.back();
} else {
history.pushState(null, null, null);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment