Categories
JavaScript Answers

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

Spread the love

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.

By John Au-Yeung

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

Leave a Reply

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