Skip to content

Commit

Permalink
Upate new tab
Browse files Browse the repository at this point in the history
  • Loading branch information
mscherrmann committed Feb 27, 2024
1 parent 7b7ea53 commit 382977c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
3 changes: 3 additions & 0 deletions _includes/scripts/misc.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@
<script src="{{ '/assets/js/no_defer.js' | relative_url | bust_file_cache }}"></script>
<script defer src="{{ '/assets/js/common.js' | relative_url | bust_file_cache }}"></script>
<script defer src="{{ '/assets/js/copy_code.js' | relative_url | bust_file_cache }}" type="text/javascript"></script>

<!-- Jupyter Open External Links New Tab -->
<script defer src="{{ '/assets/js/jupyter_new_tab.js' | relative_url | bust_file_cache }}"></script>
17 changes: 0 additions & 17 deletions assets/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,4 @@ $(document).ready(function () {
});
}
});

// Let external links in jupyter notebooks open in new tab
let jupyterNotebooks = document.getElementsByClassName("jupyter-notebook-iframe-container");
for (let i = 0; i < jupyterNotebooks.length; i++) {
let bodyElement = jupyterNotebooks[i].getElementsByTagName("iframe")[0].contentWindow.document.body;
// Get all <a> elements in the bodyElement
var links = bodyElement.getElementsByTagName("a");

// Loop through each <a> element
for (var j = 0; j < links.length; j++) {
// Check if the <a> element has an 'href' attribute
if (links[j].getAttribute("href")) {
// Set the 'target' attribute to '_blank' to open the link in a new tab/window
links[j].setAttribute("target", "_blank");
}
}
}
});
18 changes: 18 additions & 0 deletions assets/js/jupyter_new_tab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
$(document).ready(function () {
// Let external links in jupyter notebooks open in new tab
let jupyterNotebooks = $(".jupyter-notebook-iframe-container");
jupyterNotebooks.each(function () {
let iframeBody = $(this).find("iframe").get(0).contentWindow.document.body;
// Get all <a> elements in the bodyElement
let links = $(iframeBody).find("a");

// Loop through each <a> element
links.each(function () {
// Check if the <a> element has an 'href' attribute
if ($(this).attr("href")) {
// Set the 'target' attribute to '_blank' to open the link in a new tab/window
$(this).attr("target", "_blank");
}
});
});
});

0 comments on commit 382977c

Please sign in to comment.