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:
open('http://example.com/');
focus();
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.
UPDATE: By version 41 of Google Chrome,
initMouseEventseemed 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 generatedaelement with itshrefattribute set to the desiredurlIn action: fiddle
tested only on chrome