zunanje povezave se odpirajo v novem zavihku (delegiran klik pokrije tudi povezave v HTML clankov)

This commit is contained in:
folx bot
2026-08-25 11:53:28 +02:00
parent 0b60da3593
commit 2d321b4e57
3 changed files with 29 additions and 1 deletions
+26
View File
@@ -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 (
<div>
<ScrollToTop />
<ExternalLinksNewTab />
<Switch>
<Route path="/" component={Home} />
<Route path="/search" component={SearchPage} />
+2
View File
@@ -138,6 +138,8 @@ export default function EmpfangPage() {
Besuchen Sie{" "}
<a
href="https://www.folx.tv"
target="_blank"
rel="noopener"
className="text-primary hover:underline font-medium"
data-testid="link-livestream"
>