JavaScript - Page Redirect

JavaScript provides several ways to redirect a web page to another page. Here are two common methods:

1. Using the window.location property:

window.location.href = "";

In the above example, the window.location.href property is set to the URL of the page you want to redirect to. This method immediately redirects the user to the new page.

2. Using the window.location.replace method:


The window.location.replace method works similarly to the previous example, but the difference is that it replaces the current page in the history, meaning that the user cannot use the browser's back button to return to the previous page.