Skip to content

Commit

Permalink
VOTE-2035 Exclude noreferrer from .gov links (#784)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamiraMSadat authored Jun 27, 2024
1 parent 5c0c50a commit cfce77a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions web/themes/custom/votegov/src/js/external-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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');
}
}
}

Expand Down

0 comments on commit cfce77a

Please sign in to comment.