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

20

3

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.

Coldblackice

Posted 2014-12-20T00:24:16.717

Reputation: 4 774

3

Perhaps they are not actual links, in the sense that maybe the "link" is using an onclick operation which could mess with the ctrl+click. Can you give a specific example? http://meta.stackoverflow.com/questions/276138/ctrlclick-and-shiftclick-do-not-open-new-tabs-windows-in-search-results

– imtheman – 2014-12-20T00:30:23.100

@imtheman Great point, however, it doesn't appear to be the case, at least in the examples I've seen. I know this because I always hover my mouse over the link beforehand to verify that it's showing a URL in the status bar. An example is here: http://www.nationaljournal.com/white-house/the-new-white-house-fence-could-wind-up-being-really-really-tall-20141218

In the lefthand column/bar, the links to other stories appear to be their own URLS, verified by even jumping to their location in the source, however, ctrl-clicking doesn't work, instead acting as if ctrl isn't being held.

– Coldblackice – 2014-12-29T17:52:20.317

If you look at the source code for that site you'll see this for one of the links: <a class="primary" href="/congress" onclick="var x=&quot;.tl(&quot;;s_objectID=&quot;http://www.nationaljournal.com/congress_1&quot;;return this.s_oc?this.s_oc(e):true">Congress</a> – imtheman – 2014-12-29T17:55:23.353

1While it does have an href attribute, it is overwritten by the onclick event. – imtheman – 2014-12-29T17:56:36.280

Aha! Thanks. So I guess this means that the browser's status-bar display of the hovered-over URL displays the link "post-Javascript", but ctrl-clicking the link essentially executes as "pre-Javascript" (so to speak) -- does that sound right? – Coldblackice – 2014-12-29T18:05:56.987

Not quite. I'll post answer to explain a little better. – imtheman – 2014-12-29T18:13:05.287

1

I wrote a Firefox addon to fix this issue. https://github.com/danielnixon/link-fixer

– danielnixon – 2018-03-07T08:17:44.513

Voting for this bug should help (and it's really easy): Bug 55696 - "Force JavaScript link to open in new window or new tab"

– braham-snyder – 2019-06-07T13:55:46.070

Answers

10

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.

Valentin Vasilyev

Posted 2014-12-20T00:24:16.717

Reputation: 248

This isn't fully correct. While some code designs do allow an alternate trigger that forces the page to open in a new tab, other code designs prevent this. This is more common in sites with dynamic content which doesn't have typical "pages" and instead generates the pages as buttons are clicked. In this case, there are not true "links" in the page, but rather buttons that trigger behavior more like an application. – music2myear – 2018-03-15T21:33:17.627

6

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.

danielnixon

Posted 2014-12-20T00:24:16.717

Reputation: 181

1

Hi Daniel, while it's great you wrote something to address this, can you read how to recommend software in an answer, particularly the parts in bold and update your answer please? Thanks :)

– bertieb – 2018-03-07T08:43:50.400

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.

imtheman

Posted 2014-12-20T00:24:16.717

Reputation: 3 503

1Trying to find a middle-mouse on Mac. – Eduard – 2018-02-03T09:49:01.747

I wrote a Firefox addon to fix this issue. https://github.com/danielnixon/link-fixer

– danielnixon – 2018-03-07T08:16:51.260