-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,224
  • 3
  • 24
  • 48
  • 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,328
  • 4
  • 38
  • 59
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,305
  • 8
  • 35
  • 64