Why does CTRL-click not open some links in a new tab?

Sometimes while browsing, I'll ctrl-click a link to open it in a new tab. However, instead of opening in a new tab, it gets clicked and browsed to in the current tab as if I had clicked it normally without holding ctrl. I'm positive I'm holding ctrl down fully and that there is no faultiness with keyboard or mouse.

Occasionally, a new tab will be opened with the link but the current tab will also browse to the link concurrently.


Solution 1:

JavaScript behind the scenes

This happens when developers of such web pages intercept mouse clicks with JavaScript and do asynchronous network requests inside the interceptor, potentially to track your clicks. When the async network call returns, the JS does a programmatic redirect using something like: window.location.href = url;

This programmatic redirect will always load the page in the same tab, even if you hold Ctrl (Cmd on Mac).

Use MiddleMouse to override

Clicking middle button on your mouse or selecting 'open in a new tab' from the context menu will bypass the intercepting JavaScript code entirely and will open a link as if there were no JavaScript code at all.

Solution 2:

I wrote a Firefox add-on (boringly) named link-fixer to fix this. You can install from addons.mozilla.org. It requires Firefox 48.0 or later.

Quoting myself:

The default behaviour of ctrl+click, shift+click and cmd+click when clicking on links is to open the link in a new tab or new window. This behaviour is sometimes broken by careless developers. This add-on restores the default behaviour, ensuring the modifer keys are always respected.

Once installed there's nothing else you need to do. You can ctrl+click on any link and it will open in a new tab. It'll also solve the variation of the problem you describe in your second paragraph.

Solution 3:

Lets take this link as an example:

<a href="test.php" onclick="someFunction(this); return false;">Test</a>

The href attribute, in this case, is creating a pseudo link for readability (it will also allow the link to work even if JavaScript is disabled). The reason for this is because the onclick attribute always runs first. Big sites like Google do this to track clicks and to try to prevent a user from visiting malware sites. Because of this, for some reason Ctrl + Click does not work. However, if you use the middle-button on your mouse, that almost always works.