Categories
JavaScript Answers

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

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

2 replies on “How to use window.location to open URL in a new tab with JavaScript?”

Leave a Reply

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