How to open a given URL in a new tab by clicking a button with JavaScript?

Sometimes, we want to open a given URL in a new tab by clicking a button with JavaScript.

In this article, we’ll look at how to open a given URL in a new tab by clicking a button with JavaScript.

How to open a given URL in a new tab by clicking a button with JavaScript?

To open a given URL in a new tab by clicking a button with JavaScript, we call window.open with the '_blank' argument.

For instance, we write

window.open(url, "_blank");

to call window.open to open the url in a new tab with '_blank'.

Conclusion

To open a given URL in a new tab by clicking a button with JavaScript, we call window.open with the '_blank' argument.