-1

I google many times for looking for a way to open new tab on link click. If I click on link this javascript snippet open new tab and it's perfect, but if I click again new tab take focus and replaced with new content. I don't want this.

$('body').on('click', 'a.viewTextAndAnnotations', function(e) {
      e.preventDefault();
      var fullUrl = "https://www.example.com";
      window.open(fullUrl,'_newtab');
});

I would like that in second click user open second tab.

zabitstack
  • 155
  • 1
  • 6
  • Does this answer your question? [JavaScript: location.href to open in new window/tab?](https://stackoverflow.com/questions/5141910/javascript-location-href-to-open-in-new-window-tab) – Alex Ryan Apr 07 '23 at 01:12

1 Answers1

0

Please try this.

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

<a href="http://www.example.com/" onclick="javascript:openWindow(this.href);return false;">Click Me</a>
  • Yes, to use _blank is the solution. Thank you. – zabitstack Nov 18 '22 at 08:49
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 20 '22 at 22:11