FIX: with vanilla js .href and getAttribute("href") are not equal (#12609)

FIX: with vanilla js .href and getAttribute(“href”) are not equal (#12609)

With a link having an empty href: <a href>foo</a> doing element.href will give you the URL of the document, to get the same behavior than $(element).attr("href") and get “” you need to do element.getAttribute("href")

diff --git a/app/assets/javascripts/discourse/app/lib/intercept-click.js b/app/assets/javascripts/discourse/app/lib/intercept-click.js
index 6256373..7c80745 100644
--- a/app/assets/javascripts/discourse/app/lib/intercept-click.js
+++ b/app/assets/javascripts/discourse/app/lib/intercept-click.js
@@ -22,7 +22,7 @@ export default function interceptClick(e) {
   }
 
   const currentTarget = e.currentTarget;
-  const href = currentTarget.href;
+  const href = currentTarget.getAttribute("href");
 
   if (
     !href ||

GitHub sha: 89f1bb7d

1 Like

This commit appears in #12609 which was approved by awesomerobot. It was merged by jjaffeux.