Skip to content

Commit

Permalink
Navigate to new tab if link is external.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbrunvoll committed Nov 26, 2024
1 parent 74a80c0 commit 7d511db
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/layouts/shared/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type SomeLink = {
title: string;
};

const { orgId, urls, fylkeskommune } = getOrgData();
const { urls, fylkeskommune } = getOrgData();

export default function Footer({ withoutSettings = false }: FooterProps) {
const { isDarkMode, toggleDarkmode } = useTheme();
Expand Down Expand Up @@ -92,7 +92,11 @@ export default function Footer({ withoutSettings = false }: FooterProps) {
<li>
<a
href={getConfigUrl(urls.supportUrl, language)}
target={orgId === 'fram' ? undefined : '_blank'}
target={
isExternalUrl(getConfigUrl(urls.supportUrl, language))
? '_blank'
: undefined
}
rel="noreferrer"
>
{t(
Expand Down Expand Up @@ -247,3 +251,13 @@ function LanguageSelections() {
</>
);
}

function isExternalUrl(url: string) {
try {
const currentHostname = window.location.hostname;
const urlHostname = new URL(url).hostname;
return urlHostname !== currentHostname;
} catch {
return false;
}
}

0 comments on commit 7d511db

Please sign in to comment.