mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-12-23 02:28: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:
parent
9243f6689f
commit
a42554fe1d
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user