5

How to Disable Browser Back Button using JavaScript

 3 years ago
source link: https://www.codexworld.com/how-to/disable-browser-back-button-using-javascript/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Home  »  How To Guides  »  JavaScript   »   How to Disable Browser Back Button using JavaScript

How to Disable Browser Back Button using JavaScript


The browser’s back button allows the user to redirect back to the previous page that accessing before the current page. If you want to restrict users to back the previous page on your web application, the browser back button needs to be disabled. 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.

The following code snippet disables the browser back button using JavaScript.

  • Place this code into the web page where back navigation to be restricted.
window.history.pushState(null, null, window.location.href);
window.onpopstate = function () {
    window.history.go(1);
};

Leave a reply

Cancel

Comment*

Your Name*

Your Email*

Your Website


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK