window.location object of the browsers History API. This means we can modify the
location.pathname or simulate an
href action in order to tell the browser to navigate to a new destination.
location has many methods that will perform this exact same task so we will look at those in this tutorial.
Simulate an HTTP Redirect
replace method on the
location object to simulate an HTTP redirect.
Simulate a Mouse Click
Another way is to simulate a mouse click with the
href property on the
window.location.href = "https://www.example.com";
If the new page will be on the same domain we can use a relative redirect path making the program independent of the domain it is running on. Setting a new
pathname on the
location object will cause the browser to navigate to that location.
window.location.pathname = "/new";
We can use the browser window History API to navigate to the previous page.