Skip to Content
function externalLinks() {
var current = location.hostname.replace(/^www\./, "");
// One reusable accessibility description for all external links
var noticeId = "external-link-new-tab";
if (!document.getElementById(noticeId)) {
var notice = document.createElement("span");
notice.id = noticeId;
notice.className = "visually-hidden";
notice.textContent = "Opens in a new tab.";
document.body.appendChild(notice);
}
document.querySelectorAll("a[href]").forEach(function (link) {
var href = link.getAttribute("href");
if (
!href ||
href.indexOf("#") === 0 ||
/^(mailto:|tel:|javascript:)/i.test(href) ||
link.hasAttribute("download")
) {return;}
var url;
try {
url = new URL(href, location.href);
} catch (e) {return;}
if (!/^https?:$/.test(url.protocol)) {return;}
var destination = url.hostname.replace(/^www\./, "");
if (destination === current) {return;}
// Allows an intentional same-window exception if ever needed.
if (
link.getAttribute("target") === "_self" ||
link.hasAttribute("data-same-window")
) {return;}
link.setAttribute("target", "_blank");
// Preserve any existing rel values.
var rel = (link.getAttribute("rel") || "")
.split(/\s+/)
.filter(Boolean);
if (!rel.includes("noopener")) {rel.push("noopener");}
link.setAttribute("rel", rel.join(" "));
// Preserve any existing aria-describedby value.
var describedBy = (link.getAttribute("aria-describedby") || "")
.split(/\s+/)
.filter(Boolean);
if (!describedBy.includes(noticeId)) {describedBy.push(noticeId);}
link.setAttribute("aria-describedby", describedBy.join(" "));
});
}