Skip to content

Commit c425f47

Browse files
authored
Merge pull request #17 from linea-it/open-links-in-new-tabs
Modifying main.html so the external links open in new tabs.
2 parents ab2b349 + 1150dc5 commit c425f47

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

linea-theme/main.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,27 @@
4141
}
4242
}
4343
</script>
44+
45+
<!-- Force external links to open in a new tab -->
46+
<script>
47+
document.addEventListener("DOMContentLoaded", function () {
48+
// Select all links inside the documentation
49+
document.querySelectorAll("a[href]").forEach(function (link) {
50+
// Skip internal anchors and same-origin links
51+
const href = link.getAttribute("href");
52+
if (
53+
href.startsWith("#") ||
54+
href.startsWith("/") ||
55+
href.startsWith(".") ||
56+
link.hostname === window.location.hostname
57+
) {
58+
return;
59+
}
60+
// Set to open in new tab
61+
link.setAttribute("target", "_blank");
62+
link.setAttribute("rel", "noopener noreferrer");
63+
});
64+
});
65+
</script>
4466
{% endblock %}
4567

0 commit comments

Comments
 (0)