New Tab x New Window
First, just to clarify: about opening in a "new tab". If you want to open only on a new tab rather than a new window, this is not currently possible. CSS3 sets the target-new
property to deal with this, but it has not been deployed in any browser so far.
Ok, now about the main theme:
Open link in the background
You can do a workaround emulating Ctrl
+ Click
:
<a href="http://pt.stackoverflow.com/questions/40573" id="link">Link para esta questão</a>
<button onclick="simulateClick(true, false, false);">Simulate Ctrl+Click</button>
var simulateClick = function (ctrl, shift, isMiddle) {
var evt = document.createEvent('MouseEvents');
evt.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, ctrl, false, shift, false, isMiddle ? 1 : 0, null );
document.getElementById('link').dispatchEvent(evt);
}
View a similar jsFiddle
However,
This is a browser behavior , user-configured . And should be like this and only thus. Rightly so, we do not want to open the possibility to open links in the background without noticing while browsing the web! This is a user option!
More than that, even target="blank"
is only supported on certain occasions: when the user has something in progress that should not be lost with a local page redirect. An open link while playing a video, or an unsaved draft of an email in a web mail client.
The idea of all this is that we should not change the browser's natural behavior. If the user wants to open the link in the window itself, leave it. If he wants to open another, leave it. If he wants to open it on a background flap, leave it. But if he wants to open it first, leave it too.
The focus of the web application on this should be on providing the best user experience through a good layout and a smooth flow without limiting the user to choices he can in another application. This approach may even irritate the user.