JavaScript Redirect a URL Last Updated : 03 Oct, 2024 Comments Improve Suggest changes Like Article Like Report Redirecting a URL in JavaScript is nothing but sending the user from a URL to another URL. In Javascript, window.location function is used to redirect to a URL. Example 1: HTML <!DOCTYPE html> <html> <head> <title>Redirect url in Javascript</title> </head> <body> <script> let url = "https://www.geeksforgeeks.org"; window.location = url; </script> </body> </html> Output:Example 2: Below code takes an input url from the user and the url is stored in a variable through getElementById() and window.location takes the page to that url. HTML <!DOCTYPE html> <html> <head> <title>Redirect url in Javascript</title> </head> <body> <input id="url" type="text" name="url" placeholder="Enter a url here"> <input type="submit" name="button" onclick="fun()"> <script> function fun() { let url = document.getElementById("url").value; document.write("Redirecting to the url in 3 seconds..."); setTimeout(function () { window.location = url; }, 3000); } </script> </body> </html> Output:At first this will be the output, and then if the link like (https://www.geeksforgeeks.org/) is put inside the box, it will redirect to the home page of the GeeksforGeeks and will be shown like below. Steps for executing above codes: Save these files with .html extension as file_name.htmlThen open the files in a browser, it will get redirect to the GeeksforGeeks homepage. Comment More infoAdvertise with us Next Article JavaScript Redirect a URL K Kartikaybhutani Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads 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 parse URL using JavaScript ? Given an URL and the task is to parse that URL and retrieve all the related data using JavaScript. Example: URL: https://www.geeksforgeeks.org/courses When we parse the above URL then we can find hostname: geeksforgeeks.com path: /courses Method 1: In this method, we will use createElement() method 2 min read Redirecting to URL in Flask Flask is a backend server that is built entirely using Python. It is a  framework that consists of Python packages and modules. It is lightweight which makes developing backend applications quicker with its features. In this article, we will learn to redirect a URL in the Flask web application. Redi 3 min read 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 ASP Redirect Method The ASP Redirect Method is used to redirect the client to a different URL. It is a predefined method of the Response Object. Syntax: Response.Redirect URL Parameter Values: This method accepts a single parameter as mentioned above and described below: URL: It defines a Uniform resource locator which 1 min read Like