How to redirect to another url in javascript?

you can set the location of the window.

window.location = "http://domain.com/url-name";

The window.location object can be used to get the current page address (URL) and to redirect the browser to a new page.

window.location.href = "http://domain.com/url-name";

It is containing the entire URL. If changed, the associated document navigates to the new page. It can be set from a different origin than the associated document.

window.location.replace("http://domain.com/url-name");

Replaces the current resource with the one at the provided URL

Add a Comment

Your email address will not be published. Required fields are marked *