Here coder in this blog post we learn how to open a new tab in javascript on button click.
In most cases, this should happen directly in the onclick handler for the link to prevent pop-up blockers and the default “new window” behavior. You could do it this way, or by adding an event listener to your DOM
object.
HTML
<a href="javascript:;" onclick="openInNewTab('google.com')" >Open in new tab</a>
Javascript
<script>
function openInNewTab(url) {
window.open(url, '_blank').focus();
}
</script>

Brijpal Sharma is a web developer with a passion for writing tech tutorials. Learn JavaScript and other web development technology.