In this tutorial , we will show you how you can open a URL in a new Tab and not a new window. we will start by creating a function to load a given URL into a new Tab .

function openNewTab(url) {
 window.open(url, '_blank').focus();
}

//or just in one line of code
window.open(url, '_blank').focus();

We can do this directly in the onclick JavaScript Action without a function .

<div onclick="openNewTab('www.javatuto.com');">Click On</div>

When the user clicks on the button , a new tab will be open and load the URL .


Alos read : Button Onclick , Alert Input Text Value [HTML + JavaScript]

Tagged:

Laisser un commentaire