Skip to content

Commit e4cf24b

Browse files
committed
Fix issue where internal links would target="_blank"
1 parent 7e56ef7 commit e4cf24b

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

assets/js/releases/4.4.mjs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,25 @@ for (const releaseCardMedia of releaseCardMediaElements) {
336336
}
337337

338338
// target="_blank"
339+
/** @type {HTMLAnchorElement[]} */
339340
const anchors = Array.from(
340341
document.querySelector("main .release-container").querySelectorAll("a"),
341342
);
342343
for (const anchor of anchors) {
343-
anchor.target = anchor.target || "_blank";
344+
try {
345+
const anchorUrl = new URL(anchor.href);
346+
const isInternalLink =
347+
anchorUrl.protocol === window.location.protocol &&
348+
anchorUrl.host === window.location.host &&
349+
anchorUrl.port === window.location.port &&
350+
anchorUrl.pathname === window.location.pathname &&
351+
anchorUrl.hash.startsWith("#");
352+
if (!isInternalLink) {
353+
anchor.target = "_blank";
354+
}
355+
} catch (err) {
356+
const newErr = new Error("Error while setting anchor target to blank.");
357+
newErr.cause = err;
358+
console.error(newErr);
359+
}
344360
}

0 commit comments

Comments
 (0)