By default, middle-click will open a link in a new tab.
Some sites end up breaking this functionality. Middle-click ends up being the same as left-click.
Why does this happen? Is it because they program functionality for a click event, and erroneously have it apply to all clicks instead of just left-click?
Is the problem solved by explicitly giving behavior to a middle-click? Or by making the existing click behavior code apply more narrowly?
If you middle-click a folder, it will open in a new tab. This mimics the behavior of popular web browsers. If you middle-click a file, it will open the file, just as if you had double-clicked.
The scroll wheel that is located in the middle of the mouse is used to scroll up and down on any page without using the vertical scroll bar on the right hand side of a document or webpage. The scroll wheel can also be used as a third button on the mouse.
middle-click Definitions and Synonyms verb. DEFINITIONS1. 1. to press the button or wheel in the middle of a computer mouse with your finger, in order to make it possible to do something on a computer. In some programs, you can use middle-click for program-specific features.
That wheel in the middle of your mouse is good for more than just scrolling—in fact, the button can do quite a bit. Your middle-click mouse button—also known as your scroll wheel—can be an effective tab management tool in both Chrome and Firefox.
It is very easy to inadvertently prevent middle-click functionality in WebKit browsers. In WebKit browsers such as Chrome, Safari, and modern Opera, middle-clicking on a link fires a preventable click
event. This behavior differs from Firefox and IE, where middle-clicking a link will not fire a click
event.
There is actually an open bug report from 2008 on this issue, which unfortunately does not appear to have gone anywhere in the last 7 years.
So let's take a look at how easy it is to break this functionality in WebKit browsers while doing something completely ordinary.
var link = document.getElementById('link');
link.addEventListener('click', function(e) {
e.preventDefault();
alert('You clicked!');
});
<a id="link" href="http://www.example.com/">example.com</a>
Code similar to this is common when using a link to to preform other tasks, such as preventing going to the link to load the content by AJAX instead. However given WebKit's middle-click behavior, this will also prevent the native middle-click behavior.
It is possible to resolve the inconsistency by detecting which mouse button was pressed using the non-standard but widely-implemented MouseEvent.which
property. The following code will allow the middle-click function to behave as normal.
var link = document.getElementById('link');
link.addEventListener('click', function(e) {
if (e.which === 2) {
return;
}
e.preventDefault();
alert('You clicked!');
});
<a id="link" href="http://www.example.com/">example.com</a>
Unfortunately, since preserving normal behavior requires additional knowledge and implementation from the developer, unless the WebKit bug is fixed, websites that break this functionality will doubtlessly continue. More-than-likely many developers do not even know that this function of the middle-click exists, let alone testing for compatibility.
This problem has prompted the creation of at least a few different browser extensions aimed at fixing the problem. Here are the ones listed for Chrome in the bug report mentioned above.
So yes, those websites that do handle this behavior well are using some extra code to preserve the middle-click functionality in WebKit browsers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With