How to Disable Browser Back Button using JavaScript
In this article, We will share with you how to write a JavaScript function that will prevent the user to navigate back to the previous page. The browser’s back navigation can be disabled with JavaScript. Use
history.pushState()
event and onpopstate
property of the WindowEventHandlers to stop back navigation on browsers.Example:
1 2 3 4 |
window.history.pushState(state, title, window.location.href); window.onpopstate = function () { window.history.go(1); }; |