Created
May 16, 2019 13:11
-
-
Save arnaudfl/6834ec54a1f4fa08f9556e5593aa66b3 to your computer and use it in GitHub Desktop.
Intercept and disable browser's back button action
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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