

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use window.location to redirect to a different URL?
You might have encountered a situation where you clicked a URL to reach a page X but internally you were directed to another page Y. It happens due to page redirection.
It is quite simple to do a page redirect using JavaScript on the client side. To redirect your site visitors to a new page, you just need to add a line in your head section as follows.
Example
You can try to run the following code to learn how to use window.location to redirect an HTML page. Here, we will redirect to the home page
<html> <head> <script> <!-- function Redirect() { window.location.assign("https://www.tutorialspoint.com"); } //--> </script> </head> <body> <p>Click the following button, you will be redirected to home page.</p> <input type="button" value="Redirect Me" onclick="Redirect();" /> </body> </html>
- Related Questions & Answers
- How to use window.location to redirect to a different URL with JavaScript?
- How to redirect URL to the different website after few seconds?
- JavaScript - Redirect a URL
- How to automatically redirect a Web Page to another URL?
- How to use JavaScript to redirect an HTML page?
- How to use JavaScript to redirect a webpage after 5 seconds?
- How to use Meta Tag to redirect an HTML page?
- How to use Location API in Android to track your current location?
- How to specify the URL of the image to use in different situations in HTML?
- How to use Push-Location and Pop-Location command in PowerShell?
- How to use Location API in Android to track your current location using Kotlin?
- How to Use WebDriver Javascript Executor to Navigate to a URL using Postman?
- How to use URL input type in HTML?
- How to make a page redirect using jQuery?
- How to use Swift to run in background to provide current location?
Advertisements