Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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 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 −

Advertisements