How to open new tab in javascript

There are different ways in which we can open new tab in javascript.

Using anchor tag to open new tab

We can use <a> to open the new tab by setting the [target="_blank"] attribute.

<a href="https://learnersbucket.com" target="_blank">learnersbucket</a>

This will open the link in a new tab.


Using window.open()

We can achieve the same using window object and its open() method through javascript.

window.open('https://learnersbucket.com', '_blank');

It will open the given URL in the new tab.

Leave a Reply

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