How to redirect to another webpage with JavaScript

JavaScript is very extensive. While working with client side, you may occasionally want to redirect client after Ajax request success, e.g., redirect to dashboard after login successful. If you want to redirect to another page you have two options.


If you want to simulate like someone clicking on a link, use location.href

// same as user clicking on a link
window.location.href = "";


If you want to simulate an HTTP redirect, use location.replace

// same as an http redirect

JQuery $(location)

You can also redirect using JQuery library.

$(location).attr('href', '');