SteGriff

Blog

Next & Previous

How do I navigate or redirect to another page with JavaScript

A simple one, to come back from a long blogging break…

To navigate to a different site in the same browser tab:

document.location.href = targetUrl

To open a URL in a new browser tab:

window.open(targetUrl)

If you are working on a single page app, you should probably go to a router route instead. Consult your library or framework!

🗜 Byee

P.s. I am now on bluesky where my handle is this domain name 😎