2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-12-23 10:38:55 +00:00

Fix context menu actions broken on <a> elements containing nested markup

Test case: open nativefier on

```html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Test</title>
</head>
<body>
  <a href="https://google.com/">Google</a>
  <br>
  <a href="https://google.com/"><span>Google, in span</span></a>
</body>
</html>
```

* **Expected**: both links open in default browser
* **Actual under nativefier 7.0.1**: Nothing happens when clicking the second link in which the `<a>` contains a `<span>`
This commit is contained in:
Ronan Jouchet 2016-09-29 14:10:28 -04:00 committed by GitHub
parent 9243f6689f
commit a42554fe1d

View File

@ -17,6 +17,12 @@ document.addEventListener('DOMContentLoaded', () => {
window.addEventListener('contextmenu', event => { window.addEventListener('contextmenu', event => {
event.preventDefault(); event.preventDefault();
const targetElement = event.srcElement; const 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; const targetHref = targetElement.href;
if (!targetHref) { if (!targetHref) {