How to redirect to another web page using JavaScript

Learn how to redirect a web page’s visitors to another page using JavaScript in this quick and easy tutorial.

Redirecting to a web page on the same domain

To redirect a web page’s visitors to another page on the same domain:

window.location.pathname = "/new-page"

Redirecting to a web page on a different domain

To redirect a web page’s visitors to a page on a different domain:

window.location.href = "https://www.example.com/page"

That’s all there is to it!


Love our articles? HostM offers professional and helpful web hosting services with unlimited features and renewal rates that actually match our advertised rates.