diff --git a/client/src/App.tsx b/client/src/App.tsx index 6a6a814..46933a1 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -25,6 +25,31 @@ import AdminPushPage from "@/pages/admin-push"; import CookieConsent from "@/components/cookie-consent"; import MobileStickyAd from "@/components/mobile-sticky-ad"; +// Vse povezave, ki vodijo z nase domene, se odprejo v novem zavihku. Delegiran +// klik pokrije tudi povezave znotraj HTML vsebine clankov, kjer atributa +// target ne moremo nastaviti vnaprej. +function ExternalLinksNewTab() { + useEffect(() => { + const onClick = (e: MouseEvent) => { + if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return; + const el = e.target as HTMLElement | null; + const a = el && el.closest ? (el.closest("a[href]") as HTMLAnchorElement | null) : null; + if (!a) return; + const href = a.getAttribute("href") || ""; + if (!/^https?:\/\//i.test(href)) return; + let u: URL; + try { u = new URL(href, window.location.href); } catch { return; } + if (u.host === window.location.host) return; + if (a.target === "_blank") return; + e.preventDefault(); + window.open(u.href, "_blank", "noopener,noreferrer"); + }; + document.addEventListener("click", onClick); + return () => document.removeEventListener("click", onClick); + }, []); + return null; +} + function ScrollToTop() { const [location] = useLocation(); useEffect(() => { @@ -37,6 +62,7 @@ function Router() { return (
${escapeHtml(desc)}
`, chapterHtml, - `Das ganze Video auf YouTube ansehen
`, + `Das ganze Video auf YouTube ansehen
`, v.articleUrl ? `` : "", descHtml ? `