mariobros mariobros - 1 year ago 276
Javascript Question

Open new window tab without focus on new tab

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 = "";
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, true, false, false, false, 0, null);

Answer Source

What you seek is called a "pop-under" window

  • Open a new window using
  • Lose focus of the new window by using window.blur()
  • Then return focus to your existing window using window.focus()

However, it's not a guarantee as user browser settings may override this behavior, especially pop-up blockers.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download