Open new tab in background leaving focus on current tab - Chrome

As you want this for personal usage, and you do not mind using an extension, then you can write your own one.

Writing a chrome extension to achieve your required behavior is actually super easy, All you need to know is how to open/close tabs from the extension. The following page describes the whole API

Here is an example :

1 - Create a manifest.json file, and ask for the tabs permission

{
  "name": "blabla",
  "version": "0.1",
  "permissions": ["tabs"],
  "background": {
    "persistent": false,
    "scripts": ["background.js"]
  },
  "browser_action": {
    "default_title": "Open a background tab every x time"
  },
  "manifest_version": 2
}

2 - Create background.js script in the same folder

const INTERVAL = 5000;
setTimeout(function(){
    chrome.tabs.create({url: "https://www.stackoverflow.com", active: false }, tab =>{
        setTimeout(function(){
            chrome.tabs.remove(tab.id);
        },INTERVAL);
    }); 
},INTERVAL);

You can download it from here too

Note: Please note the active parameter here , it defines whether the tab should become the active tab in the window. Does not affect whether the window is focused

3 - Use the extension in chrome

  1. If you are using the download link, then unpack the archive
  2. Navigate from chrome menu to extensions
  3. Enable the developer mode in the top right corner
  4. Click on Load Unpacked button to select the extension folder
  5. The extension will run automatically

I PARTIALLY resolved using a Chrome plugin: Force Background Tab

https://chrome.google.com/webstore/detail/force-background-tab/gidlfommnbibbmegmgajdbikelkdcmcl/related?hl=en

Using that add-on the tab is opened in background without focus. The only issue is that the last used tab of the window (can be different from the tab that launches the new tab) still pops up in front of any other application in use.


You can try a kind of pop under, where you open the same url in a new tab, then change the location.href of current tab to the desired new url.

window.open(window.location.href);
window.location.href = 'http://www.google.com';

In the old days, you could do this using stuff like :

if(window.focus == false)
{
    this.focus();
}


Now you have to use extra plugins, due to abusers.
The Solution: Window Rollover:
The solution is to create another page. When you click the link, the window closes, it switches to a page that opens the window that just closed, and changes it's location to the new page.
Page 1 code:

document.getElementById("myId").onclick = function(){window.open("page2.html");window.close()}

Page 2 code:

window.open("previouspage.html");
window.location = "newpage.html";
//close the page
window.close();

I call this strategy "Window Rollover."