How To Disable Back Button In Javascript?

Asked 4 months ago
Answer 1
Viewed 105
0

The browser's Back button can redirect the user to the page previously viewed before the current page. If you want to prevent users from returning to the previous page of your web application, the browser's Back button must be disabled. Reverse browser navigation can be disabled using JavaScript. Use the history.pushState() event and the onpopstate property of WindowEventHandlers to stop backward navigation in browsers.

The snippet The code following disables the feedback browser button with JavaScript.

 

window.history.pushState(null, null, window.location.href);
window.onpopstate = function () {
    window.history.go(1);
};

 

Read Also : How can managers foster a culture of open communication and transparency within their teams?
Answered 4 months ago Matti  KarttunenMatti Karttunen