0

I have written the following code in jQuery:

  $(document).on("click", "#datatable-responsive tbody tr td button.btn", function () {
     window.open('somelinkhere', '_blank');
  });

So the problem here is when I do it like this , and it works flawlessly, the new tab that is opened gets the focus, and I don't want that to happen. Instead I would like to simulate these two keystrokes: ctrl + left mouse click

so that my main windows stays in focus and new tab gets opened...

How could I do this in jQuery?

User987
  • 3,663
  • 15
  • 54
  • 115

2 Answers2

1

One solution might be:

$(document).ready(function() {
 $("#datatable-responsive tbody tr td button.btn").click(function() {
    var thisWind = window.location;
    window.location = ('http://www.google.lt');
    window.open(thisWind, '_blank');
 });    
})

Pretty simple - first window location changed to the popup url and then the primary window reopened.

Julius Dzidzevičius
  • 10,775
  • 11
  • 36
  • 81
0

You could create an anchor element and trigger a ctrl + click on that element:

$("<a/>", {href: "https://www.google.com/"}).get(0)
    .dispatchEvent(new MouseEvent("click", {ctrlKey: true}));
AkaZecik
  • 980
  • 2
  • 11
  • 16