From 97b783db38cb7b54a22421c585b397f73b293141 Mon Sep 17 00:00:00 2001 From: Andrew Brehaut Date: Thu, 11 Mar 2021 08:16:51 +1300 Subject: [PATCH] #2371 Checks footnote target before overriding browser default behavior --- Shared/Article Rendering/newsfoot.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Shared/Article Rendering/newsfoot.js b/Shared/Article Rendering/newsfoot.js index 296c74d0b..fc5b386d5 100644 --- a/Shared/Article Rendering/newsfoot.js +++ b/Shared/Article Rendering/newsfoot.js @@ -140,12 +140,17 @@ if (targetId) break; } if (targetId === undefined) return; - + + // Only override the default behaviour when we know we can find the + // target element + const targetElement = document.querySelector(`[id='${targetId}']`); + if (targetElement === null) return; + ev.preventDefault(); installContainer(ev.target); - const content = document.querySelector(`[id='${targetId}']`).innerHTML; - void new Footnote(content, ev.target); + + void new Footnote(targetElement.innerHTML, ev.target); }); // Handle clicks on the footnote reverse link