How to Disable Browser Back Button using jQuery ? Last Updated : 29 Jul, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report While working with some privacy-related projects, we have to make sure that our programming doesn't have any kind of loopholes. In this article, we will see how we can disable the back button of the browser intentionally so that users cannot get back and access the content. We have many scenarios where we could use this kind of functionality. For example, in the payment gateways pages, we can disable the back button so that if the user unintentionally clicks on the back button the payment does not get canceled. For implementing this feature on our page we will toggle through two pages and after that, we will restrict users to get back on the first page.Example: Create two HTML files in the same folder as we use page1.html and page2.html. In page1.html, add the following code. index.html <!DOCTYPE html> <html> <head> <title>Disabling browser back button</title> <script src= "https://code.jquery.com/jquery-3.6.0.min.js" integrity= "sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"> </script> </head> <body> <a href="test2.html">Next page</a> <script> $(document).ready(function() { function disableBack() { window.history.forward() } window.onload = disableBack(); window.onpageshow = function(e) { if (e.persisted) disableBack(); } }); </script> </body> </html> On the second page, page2.html add the following code. The second page could be anything, first page is important because we are using the script on the first page. test2.html <!DOCTYPE html> <html> <body> Click on back button of browser or use the backspace key on keyboard. </body> </html> Output: You can also block the browser's back button by using Vanilla JavaScript for that you can follow this How to stop the browser back button using JavaScript article. Comment More infoAdvertise with us Next Article How to Stop Browser Back Button using JavaScript ? I iamgaurav Follow Improve Article Tags : Web Technologies JQuery jQuery-Methods jQuery-Questions Similar Reads How to Disable a Button in jQuery UI ? To disable a button in jQuery UI, we will be using disable() method which is discussed below: jQuery UI disable() method is used to completely disable the button. It returns the button element completely to its initial state. Syntax: $(".selector").button("disable") Parameters: This method does not 2 min read How to enable/disable a button using jQuery ? Enabling/disabling a button using jQuery involves altering its functionality to either accept user input or not. This is typically done by manipulating its 'disabled' property or attribute through jQuery methods like `.prop()` or .attr().To enable/disable a button using jQuery, you'll need a basic H 2 min read How to make a Disable Buttons using jQuery Mobile ? jQuery Mobile is a web based technology used to make responsive content that can be accessed on all smartphones, tablets and desktops. In this article, we will be making a Disable Button using jQuery Mobile. Approach: First, add jQuery Mobile scripts needed for your project. <link rel="stylesheet 1 min read How to Stop Browser Back Button using JavaScript ? The browser back button allows users to go back to the previous page in their browsing history. It is an essential navigation feature, but there are times when you might want to prevent users from leaving a page. Here are several methods to prevent or control back navigation using JavaScript. 1. Red 5 min read How to disable ALT key using jQuery ? jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers What is the use of it ? Disabling ALT keys have a wide range 2 min read How to disable buttons using AngularJS ? In this article, we will see how to disable the button using the particular directive in AngularJS. Sometimes, we need to disable the button, and link on the click event. This task can be accomplished by implementing the ng-disabled directive that is used to enable or disable HTML elements. Syntax: 2 min read Like