How to redirect to a webpage using JavaScript

There are two ways to redirect to a webpage using JavaScript. In the following examples, the user will be redirected to the jQuery webpage once they click the button:

1. Using location.replace()

2. Using location.href

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved