Skip to content

Commit

Permalink
Make external links open in new tab
Browse files Browse the repository at this point in the history
  • Loading branch information
nooriro committed Apr 11, 2023
1 parent ccca342 commit f8717e6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
15 changes: 15 additions & 0 deletions _includes/new-window-fix.html
@@ -0,0 +1,15 @@
<script>
// Open external links in a new window
// See https://jekyllcodex.org/without-plugin/new-window-fix/
function external_new_window() {
var anchors = document.getElementsByTagName("a");
for (var i = 0; i < anchors.length; i++) {
var a = anchors[i];
if (a.getAttribute("href") && a.hostname !== location.hostname) {
a.target = "_blank";
a.rel = "noopener";
}
}
}
external_new_window();
</script>
21 changes: 21 additions & 0 deletions _layouts/default.html
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="{{ page.lang | default: site.lang | default: "en" }}">

{%- include head.html -%}

<body>

{%- include header.html -%}

<main class="page-content" aria-label="Content">
<div class="wrapper">
{{ content }}
</div>
</main>

{%- include footer.html -%}
{%- include new-window-fix.html -%}

</body>

</html>

0 comments on commit f8717e6

Please sign in to comment.