How to Redirect to Another Webpage using JavaScript? Last Updated : 25 Oct, 2024 Comments Improve Suggest changes Like Article Like Report 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.Using window.location.hrefThe window location href property is used to set or return the complete URL of the current page. The Location href property can also be used to set the href value point to another website or point to an email address. The Location href property returns a string that contains the entire URL of the page, including the protocol. Syntaxwindow.location.href = "URL"Example: This example redirects to gfg by updating the window.location.href in defined redirect function when the button is clicked. HTML <!DOCTYPE html> <html> <body> <p> Redirect to another page using <i>window.location.href.</i> </p> <button onclick="redirect()"> Redirect to GFG </button> <!-- Redirect to Another Webpage --> <script> function redirect() { window.location.href = "https://www.geeksforgeeks.org/"; } </script> </body> </html> Output Using location.replace() MethodThe location replace() method is used to replace the current document with the specified one. This method is different from the assign() method as this removes the current document from the document history, therefore it is not possible to go back to the previous document using the ‘back’ button. Syntaxlocation.replace("URL");Example: Redirects the page to GeeksforGeeks official website by updating the location.replace in defined redirect function when the button is clicked. HTML <!DOCTYPE html> <html> <body> <p> Redirect to another page using <i>location.replace.</i> </p> <button onclick="redirect()"> Redirect to GFG </button> <!-- Redirect to Another Webpage--> <script> function redirect() { location.replace("https://www.geeksforgeeks.org/"); } </script> </body> </html> Output Use Cases to Redirect to Another Webpage1. How to redirect to a relative URL in JavaScript?To redirect to a relative URL in JavaScript, you could use window.location.href. It is a property in JavaScript that represents the complete URL of the current page. It can be used to get the current URL or to navigate to a new URL by assigning a new URL to it.2. How to Redirects to Another WebPage if User Idle for 10 Seconds in JavaScriptWe will use JavaScript to redirect the web page to another web page if the user is ideal for 10 seconds.3. How to redirect browser window back using JavaScript ?There are two approaches used to redirect the browser window back:Using history.back() MethodUsing history.go() Method Comment More infoAdvertise with us Next Article How to Redirect to Another Webpage using JavaScript? P ProgrammerAnvesh Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads How to redirect to another webpage in HTML? It is often required to redirect to another webpage on loading a webpage, for example, due to the contents being moved to the new webpage. Demonstrated here are two simple methods to redirect to another webpage on load. Method-1: Using http-equiv attribute of the meta tag in HTML.Syntax:<meta htt 2 min read How to redirect browser window back using JavaScript ? 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 s 2 min read How to Redirects to Another WebPage if User Idle for 10 Seconds in JavaScript ? In this article, we will create a webpage that redirects to another page if the user is idle for more than one minute. We will use JavaScript to redirect the web page to another web page if the user is ideal for 10 seconds. Approach: To make this, we will use setTimeout() and clearTimeout() methods. 2 min read How to redirect to multiple websites with a delay using JavaScript ? We have given multiple websites and the task is to redirect to multiple websites with some delay using JavaScript. We will use setTimeout() function to delay the website. setTimeout() Function: The setTimeout() method executes a function, after waiting a specified number of milliseconds. The first p 2 min read How to redirect to a relative URL in JavaScript? To redirect to a relative URL in JavaScript, you could use window.location.href. It is a property in JavaScript that represents the complete URL of the current page. It can be used to get the current URL or to navigate to a new URL by assigning a new URL to it. Approach HTML Structure:The HTML file 2 min read How to Redirect to Another Page in ReactJS ? In ReactJS, when you need to move users from one page to another, we can use the built-in React Router library, which is designed specifically for handling navigation within a React application.ApproachUse the Navigate component: In React Router v6, the Navigate component helps us to redirect users 6 min read How to Redirect to Another Page After 5 Seconds using jQuery ? In this article, we will learn, how to redirect to another page or URL after a specified time in jQuery. The built-in function used for performing the action is as follows. The setTimeout(callback, delay) function takes two parameters a callback and a time in milliseconds. When this method is called 1 min read How to get URL Parameters using JavaScript ? To get URL parameters using JavaScript means extracting the query string values from a URL. URL parameters, found after the ? in a URL, pass data like search terms or user information. JavaScript can parse these parameters, allowing you to programmatically access or manipulate their values.For getti 3 min read How to Get the Current URL using JavaScript? Here are two different methods to get the current URL in JavaScript.1. Using Document.URL PropertyThe DOM URL property in HTML is used to return a string that contains the complete URL of the current document. The string also includes the HTTP protocol such as ( http://).Syntaxdocument.URLReturn Val 1 min read Like