Skip to content

Instantly share code, notes, and snippets.

@arnaudfl
Created May 16, 2019 13:11
Show Gist options
  • Save arnaudfl/6834ec54a1f4fa08f9556e5593aa66b3 to your computer and use it in GitHub Desktop.
Save arnaudfl/6834ec54a1f4fa08f9556e5593aa66b3 to your computer and use it in GitHub Desktop.
Intercept and disable browser's back button action
// How to use it: import this function from another file and run it
// import DisableBack from 'BrowserHistory';
// DisableBack();
// intercept browser's back button action and disable it
function DisableBack() {
window.history.pushState(null, null, window.location.href);
window.onpopstate = function onPopState() {
window.history.go(1);
};
}
export default DisableBack;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment