Skip to content

Commit

Permalink
Link external test.
Browse files Browse the repository at this point in the history
  • Loading branch information
g-pacheco committed Apr 16, 2024
1 parent 0df5086 commit 6bf63b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion _includes/button.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% if button.link or button.icon or button.text %}
<div class="button-wrapper">
<a
class="button" target="_blank"
class="button"
href="{{ button.link | replace: "$LINK", button.link | relative_url }}"
{% if button.tooltip %}
data-tooltip="{{ button.tooltip }}"
Expand Down
20 changes: 20 additions & 0 deletions _scripts/ext-links.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
make all external links open in a new tab
*/

{
const onLoad = () => {
// for each link
const links = document.querySelectorAll("a");
for (const link of links)
try {
// if link absolute and different domain
if (new URL(link.href).hostname !== new URL(window.location).hostname)
// make link open in new tab
link.setAttribute("target", "_blank");
} catch (error) {}
};

// after page loads
window.addEventListener("load", onLoad);
}

0 comments on commit 6bf63b3

Please sign in to comment.