Index: ui/webui/resources/js/util.js |
diff --git a/ui/webui/resources/js/util.js b/ui/webui/resources/js/util.js |
index 293205804389a21425c26bc0c26756533d9e42ea..ee6cd40a7d9d28df6767e7bfba459fa9ae68186b 100644 |
--- a/ui/webui/resources/js/util.js |
+++ b/ui/webui/resources/js/util.js |
@@ -216,26 +216,44 @@ document.addEventListener('click', function(e) { |
if (e.defaultPrevented) |
return; |
+ var eventPath = e.path; |
+ var anchor = null; |
+ if (eventPath) { |
+ for (var i = 0; i < eventPath.length; i++) { |
+ var element = eventPath[i]; |
+ if (element.tagName === 'A' && element.href) { |
+ anchor = element; |
+ break; |
+ } |
+ } |
+ } |
+ |
+ // Fallback if Event.path is not available. |
var el = e.target; |
- if (el.nodeType == Node.ELEMENT_NODE && |
+ if (!anchor && el.nodeType == Node.ELEMENT_NODE && |
el.webkitMatchesSelector('A, A *')) { |
while (el.tagName != 'A') { |
el = el.parentElement; |
} |
+ anchor = el; |
+ } |
- if ((el.protocol == 'file:' || el.protocol == 'about:') && |
- (e.button == 0 || e.button == 1)) { |
- chrome.send('navigateToUrl', [ |
- el.href, |
- el.target, |
- e.button, |
- e.altKey, |
- e.ctrlKey, |
- e.metaKey, |
- e.shiftKey |
- ]); |
- e.preventDefault(); |
- } |
+ if (!anchor) |
+ return; |
+ |
+ anchor = /** @type {!HTMLAnchorElement} */(anchor); |
+ if ((anchor.protocol == 'file:' || anchor.protocol == 'about:') && |
+ (e.button == 0 || e.button == 1)) { |
+ chrome.send('navigateToUrl', [ |
+ anchor.href, |
+ anchor.target, |
+ e.button, |
+ e.altKey, |
+ e.ctrlKey, |
+ e.metaKey, |
+ e.shiftKey |
+ ]); |
+ e.preventDefault(); |
} |
}); |