How to Redirect to Another Page in JavaScript

March 10, 2026 by Talal khalid

You can redirect users to another page using JavaScript by setting the window.location.href property. This method immediately sends visitors to a new URL.

JavaScript Code

<script>
window.location.href = "https://example.com";
</script>

Redirect After a Delay

You can also redirect after a delay using setTimeout.

<script>
setTimeout(function() {
  window.location.href = "https://example.com";
}, 3000);
</script>

This example redirects users after 3 seconds.

Shares