1

Can I used javascript to open a new tab in the browser, but not switch to it?

Now i use:

<script>window.open("url")</script>

UPD May be I'm stupid, but

<script>
function openWin(){
    popupWindow = window.open("url");
    popupWindow.blur();
}
openWin()
</script>

dos'n work... It's opening tab, but focus on it.

Atterratio
  • 445
  • 2
  • 9
  • 25
  • 1
    possible duplicate of [open a new browser tab in background programmatically](http://stackoverflow.com/questions/7386208/open-a-new-browser-tab-in-background-programmatically) – Felix Kling Aug 22 '13 at 20:58
  • 1
    and [Open a new tab in the background?](http://stackoverflow.com/q/10812628/218196). – Felix Kling Aug 22 '13 at 20:58
  • 1
    and [Open a new tab with javascript but stay on current tab](http://stackoverflow.com/q/6213807/218196) and probably some more [of those](http://stackoverflow.com/search?q=[javascript]+open+tab+in+background). – Felix Kling Aug 22 '13 at 20:59
  • ...and an awful practice. I can't think that there is a "great" reason to do this. – jterry Aug 22 '13 at 20:59
  • It's up to the browser, not you, whether or not new tabs are focused. – gen_Eric Aug 22 '13 at 21:34

2 Answers2

1

You could create an event (ctrl + click) to do this, eg:-

var event = document.createEvent("MyEvent");
var a = document.createElement("a");
a.href = "http://www.stackoverflow.com/";
event.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, true, false, false, false, 0, null);
a.dispatchEvent(event);

event.initMouseEvent

Cœur
  • 37,241
  • 25
  • 195
  • 267
Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
1

The JavaScript blur event takes focus away from the window, so you can open a new window and then take focus away from it I believe.

http://www.w3schools.com/jsref/met_win_blur.asp

Djave
  • 8,595
  • 8
  • 70
  • 124