How to Open a URL in a New Tab Using Javascript?
To open a URL in a new tab using Javascript, you can use the window.open() method and specify the target as "_blank". Here is an example:
<button onclick="openNewTab()">Open Google in a new tab</button>
<script>
function openNewTab() {
window.open("http://www.google.com", "_blank");
}
</script>
In this example, when the button is clicked, the openNewTab() function is called which uses the window.open() method to open the URL in a new tab. The second parameter "_blank" tells the browser to open the URL in a new tab, instead of the current tab.