From d8711c197de79cb74e2de2c18bb23baeef3387fb Mon Sep 17 00:00:00 2001 From: Oscar Najera Date: Sun, 9 Feb 2025 22:04:25 +0100 Subject: [FIX] current targe when link wraps other elements Many times the A tag wraps many things. It happened that those contained element where the target and so the link would be undefined as they don't have href. The correct links resides on event.currentTarget.href. A second bug happens, on links to externals which I set to open in new window. Somehow, on the return of register-visit, the event has no currentTarget and so, it is the correct way to use event.target.target to figure out if I wanted to open a new window. --- webstats/stats.paren | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'webstats/stats.paren') diff --git a/webstats/stats.paren b/webstats/stats.paren index 4721272..6491020 100644 --- a/webstats/stats.paren +++ b/webstats/stats.paren @@ -13,14 +13,15 @@ (when (or (= 1 (@ event which)) (= 2 (@ event which))) (chain event (prevent-default)) - (let ((link (getprop event 'target 'href))) + (let ((link (getprop event 'current-target 'href))) (chain (register-visit (create :click link :page (@ document location href))) (finally (lambda () - (if (= 1 (@ event which)) - (setf (@ window location href) link) - (chain window (open link "_blank"))))))))) + (if (or (= 2 (@ event which)) + (eql (@ event target target) "_blank")) + (chain window (open link "_blank")) + (setf (@ window location href) link)))))))) (defun instrument-links () (for-of (link ((@ document query-selector-all) "a")) -- cgit v1.2.3