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.
2 replies on “How to use window.location to open URL in a new tab with JavaScript?”
The explanation misleads the title. You’re not using window.location(); you are using window.open(). So your article doesn’t hornor the title.
Hahaha, what? I’m with Gilbert on this one… change the title…