16

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.

  • 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? meta.stackoverflow.com/questions/276138/… – imtheman Dec 20 '14 at 0:30
  • @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: nationaljournal.com/white-house/… 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 Dec 29 '14 at 17:52
  • 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 Dec 29 '14 at 17:55
  • 1
    While it does have an href attribute, it is overwritten by the onclick event. – imtheman Dec 29 '14 at 17:56
  • 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 Dec 29 '14 at 18:05
7

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.

  • 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 Mar 15 '18 at 21:33
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.

3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.