Skip to content

Commit

Permalink
Adds func externalLinksOpenNewTab() so all hyperlinks open in new tab…
Browse files Browse the repository at this point in the history
…, preserving app as open.

Signed-off-by: michael vincerra <[email protected]>
  • Loading branch information
mvincerx committed Nov 9, 2023
1 parent bc239ad commit 8ca8875
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/docs/_static/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ document.addEventListener('DOMContentLoaded', function () {
showTotalRecords();
attachSearch();
filterPaginatedData();
externalLinksOpenNewTab();
lastUpdated();
})
});
Expand Down Expand Up @@ -366,3 +367,18 @@ function renderCards(data) {
}
})
}

function externalLinksOpenNewTab() {

const hyperlinks = document.querySelectorAll("a[href^='https://'], a[href^='http://']");
const host = window.location.hostname;
const internalLink = link => new URL(link).hostname === host

hyperlinks.forEach(link => {
if (internalLink(link)) return
link.setAttribute("target", "_blank")
link.setAttribute("rel", "noopener")
})

};

0 comments on commit 8ca8875

Please sign in to comment.