by Sai gowtham

How to redirect to another page in JavaScript

Home » javascript » How to redirect to another page in JavaScript

Consider we have contact form whenever a user submits a form we redirect the user from contact page to home page or some other page. In such cases, we can use href property or replace method in javascript.


window.location.href = ""

Just open your console and run above code to redirect from the current page to

Using replace method


If we use the replace method current page will not be saved in the session history, so that, we can’t use the back button to navigate back to previous page.

How to redirect from one page to another page by using a button click



<button class="btn" >Click</button>


const btn = document.querySelector('.btn')

    window.location.href = ""