Fix context menu actions broken on <a> elements containing nested markup (#263)

Merge branch 'ronjouch-patch-1' into development
This commit is contained in:
Goh Jia Hao 2016-10-09 14:16:59 +08:00
commit 2892e09db0
1 changed files with 7 additions and 1 deletions

View File

@ -16,7 +16,13 @@ document.addEventListener('DOMContentLoaded', () => {
window.addEventListener('contextmenu', event => {
event.preventDefault();
const targetElement = event.srcElement;
let targetElement = event.srcElement;
// the clicked element is the deepest in the DOM, and may not be the <a> bearing the href
// for example, <a href="..."><span>Google</span></a>
while (!targetElement.href && targetElement.parentElement) {
targetElement = targetElement.parentElement;
}
const targetHref = targetElement.href;
if (!targetHref) {