Bug 70070 - Middle click on some links opens link in current tab
Summary: Middle click on some links opens link in current tab
Status: UNCONFIRMED
Alias: None
Product: WebKit
Classification: Unclassified
Component: UI Events (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC Windows 7
: P2 Normal
Assignee: Nobody
URL: http://www.bbc.co.uk/news/magazine-15...
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-13 16:01 PDT by Will Hirsch
Modified: 2012-04-25 10:35 PDT (History)
5 users (show)

See Also:


Attachments
BBC News Article (1.71 MB, application/x-webarchive)
2011-10-15 18:28 PDT, Daniel Bates
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Will Hirsch 2011-10-13 16:01:53 PDT
For some reason, this applies to all external links on the  BBC News website. See for example the linked URL, the link "Nuclear Threat Initiative". Middle-clicking on these links opens in the current tab like left-clicking.

Other means of opening in a new tab, including Ctrl+Click open in a new tab as normal.

I can't see what it is about these links which trigger this bug. Middle-clicking also works on all other links on the BBC News website - it is only links to non-BBC sources - and cross-domain links on other sites work fine.
Comment 1 Daniel Bates 2011-10-15 18:28:16 PDT
Created attachment 111160 [details]
BBC News Article

For historical preservation, a web archive of <http://www.bbc.co.uk/news/magazine-15288975> as seen on 10/15/2011.
Comment 2 Daniel Bates 2011-10-15 19:11:15 PDT
From observation and briefly looking at the source code for the page in Web Inspector, this BBC News page captures mouse click events and selectively overrides the default browser behavior using document.location.href.

I don't have a mouse with a middle mouse button. So, I programmatically generated a DOM Click event for the middle mouse button and dispatched it at the example hyperlink using Web Inspector and the following script (*):

var link = document.querySelector("a[href='http://www.nti.org/e_research/e3_88.html']");
var mouseEvent = document.createEvent("MouseEvents");
mouseEvent.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 1, null);
link.dispatchEvent(mouseEvent);

Using Xcode's debugger (**) and middle clicking on the example hyperlink mentioned in the bug description (comment 0) we see that Location::setHref(), <http://trac.webkit.org/browser/trunk/Source/WebCore/page/Location.cpp?rev=96779#L155>, is ultimately called; => BBC News captures the DOM Click event and ultimately overrides the value of document.location.href with <http://www.nti.org/e_research/e3_88.html> (the URL associated with this hyperlink). Hence, we navigate the current page to this new URL instead of opening a new tab (the default browser behavior).

Consistent with the bug description, middle clicking on a non-external hyperlink, say for the article "Do we understand 'risk' of mobile phone use?", doesn't override the value of document.location.href and the article opens in a new tab.

(*) See <https://developer.mozilla.org/en/DOM/event.initMouseEvent>/<http://www.w3.org/TR/DOM-Level-3-Events/#events-event-type-initMouseEvent> for a composite breakdown of the arguments to initMouseEvent().

(**) The page at <http://www.bbc.co.uk/news/magazine-15288975> loads many obfuscated JavaScript scripts. These obfuscated script make it difficult to identify the script or snippet that is responsible for this behavior. If I have additional time, I'll try to identify the script or snippet that is responsible for the observed behavior.
Comment 3 Alexey Proskuryakov 2011-10-17 12:18:43 PDT
I suspect that this is a Safari bug, not a WebKit one.
Comment 4 Will Hirsch 2011-10-17 13:05:33 PDT
If it is, then there's an identical one in Chrome - reproduces in Chrome 16.0.904.0 dev-m but not in IE or Firefox.
Comment 5 Will Hirsch 2012-04-25 02:29:17 PDT

*** This bug has been marked as a duplicate of bug 22382 ***
Comment 6 Alexey Proskuryakov 2012-04-25 09:51:19 PDT
This may be related to bug 22382, but calling this a duplicate is inaccurate unless a patch for that bug lands and fixes both.
Comment 7 Will Hirsch 2012-04-25 10:35:41 PDT
The web script behaves exactly as it should for a click event fired on middle click. The only difference with behaviour in other engines is that the event is not fired.

The script even performs some validation on the event (istats-1.js, line 897) to detect clicks aimed at new tabs and windows with modifier keys and refrain from changing the window href on these clicks - it just doesn't check e.button.

In other words, this is a specific example of behaviour that bug 22382 seeks to define. You can classify it as you please but I assumed a bug that is nothing more than a reproduction case for another bug would be considered unnecessary clutter.