Skip to content

Commit b361cd4

Browse files
committed
add js to open external links in new tab
1 parent 01c7b75 commit b361cd4

3 files changed

Lines changed: 17 additions & 0 deletions

File tree

_config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ footer:
6464
icon: "fab fa-linkedin"
6565
url: "https://www.linkedin.com/in/jake-dearborn-15408652/"
6666

67+
6768
# Defaults for pages
6869
defaults:
6970
- scope:
@@ -76,6 +77,9 @@ defaults:
7677
comments: false
7778
share: false
7879
related: false
80+
# Add custom footer include for JS
81+
footer:
82+
custom: custom-footer
7983

8084
# Markdown settings
8185
markdown: kramdown

_includes/custom-footer.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<script src="/assets/js/open-external-in-new-tab.js"></script>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// This script makes all external links open in a new tab (target="_blank")
2+
// It runs after the DOM is loaded.
3+
document.addEventListener("DOMContentLoaded", function() {
4+
var links = document.querySelectorAll('a[href^="http"], a[href^="mailto:"]');
5+
links.forEach(function(link) {
6+
// Only set target for links not on the same domain
7+
if (!link.href.startsWith(window.location.origin)) {
8+
link.setAttribute('target', '_blank');
9+
link.setAttribute('rel', 'noopener noreferrer');
10+
}
11+
});
12+
});

0 commit comments

Comments
 (0)