How to redirect browser window back using JavaScript ? Last Updated : 02 Aug, 2024 Comments Improve Suggest changes Like Article Like Report Redirecting a browser window back to the previous page using JavaScript is a common task for web developers looking to enhance user navigation. This guide will cover the simple yet important methods available in JavaScript to achieve this functionality, ensuring a smooth user experience. There are several approaches available in JavaScript to redirect the browser window back which are as follows:Table of Content Using history.back() MethodUsing history.go() Method1. Using history.back() MethodThe back() method of the window.history object is used to go back to the previous page in the current session history. In case there is no previous page, this method does not call anything. The onclick event can be specified with this method to go back one page in history. Syntax:history.back();Example: This example uses history.back() method to redirect the browser to the previous page. HTML <!DOCTYPE html> <html> <head> <title>DOM History.back() Method</title> <style> h1 { color: green; } body { text-align: center; } </style> </head> <body> <h1>GeeksforGeeks</h1> <h2>DOM History.back() Method</h2> <p>For going to the previous URL in the history, double-click the "Go back" button: </p> <button onClick="history_back()">Go back</button> <script> function history_back() { window.history.back(); } </script> </body> </html> Output:2. Using history.go() MethodThe history.go() Method of the window.history object is used to load a page from the session history. It can be used to move forward or backward using the value of the delta parameter. A positive delta parameter means that the page would go forward in history. Similarly, a negative delta value would make the page go back to the previous page. This method can be used with ‘-1’ as the delta value to go back one page in history. The onclick event can be specified with the method to go back one page in history. Syntax:history.go(number\URL);Example: This example uses window.history.go() method to redirect the browser into previous page. HTML <!DOCTYPE html> <html> <head> <title>DOM History.go() Method</title> <style> h1 { color: green; } body { text-align: center; } </style> </head> <body> <h1>GeeksforGeeks</h1> <h2>DOM History.go() Method</h2> <p> For going to the previous URL in the history, double click the "Go to the previous URL" button: </p> <button onClick="history_goback()"> Go to the previous URL </button> <script> function history_goback() { window.history.go(-1); } </script> </body> </html> Output:Note: This method will not work if the previous page does not exist in the history list. Supported Browsers: Google ChromeMicrosoft EdgeFirefoxApple SafariOpera Comment More infoAdvertise with us Next Article How to redirect browser window back using JavaScript ? P priyanshid1 Follow Improve Article Tags : Technical Scripter JavaScript Web Technologies JavaScript-Misc JavaScript-Questions +1 More Similar Reads How to Redirect to Another Webpage using JavaScript? JavaScript can redirects the users from current page to another webpage (different URL) with and without requiring any manual action (like clicking a link). To redirect to another weboage in JavaScript we need to manipulate the window.location object and it will allow us to navigate programmatically 2 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 close current tab in a browser window using JavaScript? In this article, we will see how to close the current tab in a browser window using JavaScript. window.close() methodTo make this, we will use window.close() method.  This method is used to close the window which is opened by the window.open() method. Syntax:window.close();But accounting for a secur 1 min read How to make browser to go back to previous page using JavaScript ? There are two popular methods to navigate a browser back to the previous page. These methods allow easy navigation in a web session's history, offering simple and effective ways to move backward or forward through a user's browsing history.These are the following two ways: Table of ContentUsing hist 3 min read How to open URL in a new window using JavaScript? In HTML, the anchor tag (<a>) is used to open new windows and tabs in a very straightforward manner. However, there are situations where you need to achieve the same functionality using JavaScript. This is where the window.open() method becomes useful.The window.open() method is used to open a 3 min read Like