How to open link / url in new tab using JavaScript

Simple html ‘a>’ tag with attribute “_blank” provides an easy and simple way to open the linked URL in the new browser window, We mostly use this method for external link so that visitor couldn’t leave actual website. But sometime you need to open new tab using javascript, you can simply use following javascript function to open link in new tab.



Here I am going to use javascript window.open() function, Next use _blank in the second parameter of method window.open() to open a URL in a new tab using JavaScript. The following JavaScript code will open http://www.iamrohit.in in a new tab or window of browser.

<script>
function openNewTab(url) {
  var win = window.open(url, '_blank');
  win.focus();
}
</script>
<span onclick="openNewTab('www.iamrohit.in');">Click To Open My Public NoteBook</span>