How to use window.location to open URL in a new tab with JavaScript?

Sometimes, we want to use window.location to open URL in a new tab with JavaScript.

In this article, we’ll look at how to use window.location to open URL in a new tab with JavaScript.

How to use window.location to open URL in a new tab with JavaScript?

To use window.location to open URL in a new tab with JavaScript, we call window.open with '_blank' as the 2nd argument.

For instance, we write

window.open("https://example.com", "_blank");

to call window.open with the URL of the page we want to open and '_blank' to open it in a new tab.

Conclusion

To use window.location to open URL in a new tab with JavaScript, we call window.open with '_blank' as the 2nd argument.