From cfce77a02630ed1e07943ac00ac7dd713b6a53f2 Mon Sep 17 00:00:00 2001 From: SamiraMSadat <108487505+SamiraMSadat@users.noreply.github.com> Date: Thu, 27 Jun 2024 07:21:05 -0600 Subject: [PATCH] VOTE-2035 Exclude noreferrer from .gov links (#784) --- web/themes/custom/votegov/src/js/external-links.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/web/themes/custom/votegov/src/js/external-links.js b/web/themes/custom/votegov/src/js/external-links.js index 6758bf2e5..4252e501a 100644 --- a/web/themes/custom/votegov/src/js/external-links.js +++ b/web/themes/custom/votegov/src/js/external-links.js @@ -5,7 +5,7 @@ (() => { // Enable external links behavior. - // `extlinkjs-ignore` attribute should be added to all icons in order to not render the uswds external links icon + // `extlinkjs-ignore` attribute should be added to all icons in order to not render the uswds external links icon const externalLinks = document.querySelectorAll('a[href^="https"]:not([extlinkjs-ignore])'); const title_translated = Drupal.t('External link opens in new window'); @@ -15,7 +15,9 @@ externalLinks[i].classList.add('usa-link--external'); externalLinks[i].setAttribute('target', '_blank'); externalLinks[i].setAttribute('title', title_translated); - externalLinks[i].setAttribute('rel', 'noreferrer'); + if (!new URL(externalLinks[i].href).hostname.endsWith(".gov")) { + externalLinks[i].setAttribute('rel', 'noreferrer'); + } } }