-4

I followed this post and it works fine:

How can i make a link do some jquery then go to destination

How can i add the equivalent to target=”_blank”?

I want the destination page to open in a new tab

bart2puck
  • 2,432
  • 3
  • 27
  • 53
  • 1
    Possible duplicate of [JavaScript: location.href to open in new window/tab?](https://stackoverflow.com/questions/5141910/javascript-location-href-to-open-in-new-window-tab) – TimSch Oct 12 '18 at 13:44

2 Answers2

1

You can use window.open ike this:

window.open('url/to/page', '_blank');
kapantzak
  • 11,610
  • 4
  • 39
  • 61
1

You can use window.open as following

$('#link').click(function(e){
    e.preventDefault();
    alert('you clicked'); 
    window.open($(this).attr('href'),'_blank');
});

The first parameter will get url from anchor tag href attribute and then second will add target _blank property.

Ayaz Ali Shah
  • 3,453
  • 9
  • 36
  • 68