
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to redirect to another webpage with JavaScript?
To redirect to another webpage using JavaScript, the code is as follows −
Example
<!DOCTYPE html> <html> <head> <h1>Redirect to a Webpage Example</h1> <button class="redirectBtn">Redirect</button> <h2>Click the above button to Redirect to another Webpage</h2> <script> document .querySelector(".redirectBtn") .addEventListener("click", redirectFunction); function redirectFunction() { location.href("https://tutorialspoint.com/"); } </script> </body> </html>
Output
The above code will produce the following output −
On clicking the “Redirect” button we will be redirected to a new site −
- Related Articles
- How to redirect to another webpage using JavaScript?
- How to redirect to another webpage using jQuery?
- How to use JavaScript to redirect a webpage after 5 seconds?
- Bash Terminal Redirect to another Terminal
- How to automatically redirect a Web Page to another URL?
- How to use window.location to redirect to a different URL with JavaScript?
- How to link a submit button to another webpage using HTML?
- How to use JavaScript to redirect an HTML page?
- How do I redirect my web page with JavaScript?
- How to redirect URLs with your Hosting Account?
- How to add Summernote Editor to the webpage in Javascript?
- How to perform vertical scrolling of a webpage with Javascript executor in Selenium with python?
- How to create Pay Roll Management Webpage using JavaScript?
- How to use JavaScript to load a webpage after 5 seconds?
- How to redirect if JavaScript is not enabled in a browser?

Advertisements