Skip to content
Advertisement

Open a new tab in the background?

Using javascript, I want to open a new page in a different tab, but remain focused on the current tab. I know I can do it like this:

JavaScript

However, when I do this in chrome, it flashes the new tab for a moment before switching back to the current tab. I want to avoid this.

The application is a personal bookmarklet, so it only has to work in the latest Chrome.

Advertisement

Answer

UPDATE: By version 41 of Google Chrome, initMouseEvent seemed to have a changed behavior, and so this answer no longer works. Thanks to @Daniel Andersson for his comment.

this can be done by simulating ctrl + click (or any other key/event combinations that open a background tab) on a dynamically generated a element with its href attribute set to the desired url

In action: fiddle

JavaScript

tested only on chrome

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement