1

There's a way to open new tab (using jQuery or Javascript) and remain on main page?

i've tried this code but focus is on opened tab:

function openNewBackgroundTab(){
  var a = document.createElement("a");
  a.href = "http://www.google.com/";
  var evt = document.createEvent("MouseEvents");
  evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, true, false, false, false, 0, null);
  a.dispatchEvent(evt);
}
mariobros
  • 859
  • 4
  • 12
  • 31
  • 2
    Are you about to invent the popunder ad? – Brian Oct 28 '16 at 14:34
  • 2
    Sounds exactly like a popunder, and most browsers will probably block it. – adeneo Oct 28 '16 at 14:34
  • As far as I know, this is pretty much handled solely at the browser's discretion, and nearly every browser chooses to shift focus to the new tab. One option is to re-open your page in a new tab and then redirect the original tab to the new location. However, that is somewhat undesirable, in my opinion. – Spencer D Oct 28 '16 at 14:36

0 Answers0