title: Open new tab in background leaving focus on current tab - Chrome
body: <p>How to execute in JavaScript a CTRL + click on a link that works in the latest version of Chrome (v68)?</p>
  
  <p>Context - I'm running a JavaScript script that opens a certain tab at certain hours of the day (and closes it after a few minutes). I'm trying to get it to open the tab in background leaving the focus on the current tab that I'm using. </p>
  
  <p>The tab opened programmatically leads Chrome to pop up even when minimized, quite disrupting.</p>
  
  <p>These <a href="https://stackoverflow.com/questions/2181464/i-need-to-open-a-new-window-in-the-background-with-javascript-and-make-sure-the">old solutions</a> that I found here on Stack Overflow don't work with the latest version of Chrome.</p>
  
  <p>Manually CTRL + clicking a link achieves the effect that I want (tab is opened in background). Can this be achieved programmatically on the latest version of Chrome?</p>
  
  <hr>
  
  <p>The following code does not work anymore with the latest version of Chrome..</p>
  
  <pre><code>const openNewBackgroundTab = (url) =&gt; {
    const anchor = document.createElement("a");
    anchor.href = url;
    document.body.appendChild(anchor);
    const evt = document.createEvent("MouseEvents");    
    // the tenth parameter of initMouseEvent sets ctrl key
    evt.initMouseEvent(
      "click", true, true, window, 0, 0, 0, 0, 0,
      true, false, false, false, 0, null
    );
    anchor.dispatchEvent(evt);
  }
  openNewBackgroundTab('https://stackoverflow.com');
  </code></pre>
  
  <p>.. the new tab still gets the focus.</p>
  
  <hr>
  
  <p><strong>STEPS to reproduce:</strong></p>
  
  <ul>
  <li>Open window 1 and in console execute:</li>
  </ul>
  
  <p><code>   let winStacko;
      setTimeout(() => { winStacko = open('<a href="https://www.stackoverflow.com">https://www.stackoverflow.com</a>'); }, 30 * 1000);
      setTimeout(() => winStacko.close(), 2 * 60 * 1000);
  </code></p>
  
  <ul>
  <li>Open window 2 within 30 seconds after executing the script</li>
  </ul>
  
  <p><strong>DESIRED behavior:</strong></p>
  
  <ul>
  <li>Window 2 has the focus for the whole time while the background tab is opened and then closed.</li>
  </ul>