From c4cc39d7c2d03b1d144a75f24400373e0158b703 Mon Sep 17 00:00:00 2001 From: Scherrmann Date: Tue, 27 Feb 2024 12:01:20 +0100 Subject: [PATCH 1/2] Add functionality to open external links in jupyter notebooks in new tab --- _includes/scripts/misc.liquid | 3 +++ assets/js/jupyter_new_tab.js | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 assets/js/jupyter_new_tab.js diff --git a/_includes/scripts/misc.liquid b/_includes/scripts/misc.liquid index 61223b17acf4..86f81fa69139 100644 --- a/_includes/scripts/misc.liquid +++ b/_includes/scripts/misc.liquid @@ -31,3 +31,6 @@ + + + \ No newline at end of file diff --git a/assets/js/jupyter_new_tab.js b/assets/js/jupyter_new_tab.js new file mode 100644 index 000000000000..c7f8208a83db --- /dev/null +++ b/assets/js/jupyter_new_tab.js @@ -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 elements in the bodyElement + let links = $(iframeBody).find("a"); + + // Loop through each element + links.each(function () { + // Check if the 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"); + } + }); + }); +}); \ No newline at end of file From 6714eec062fdc0c8a1981183886acce0afbe8184 Mon Sep 17 00:00:00 2001 From: mscherrmann Date: Tue, 27 Feb 2024 16:14:22 +0100 Subject: [PATCH 2/2] fix prettier formatter complaints --- _includes/scripts/misc.liquid | 2 +- assets/js/jupyter_new_tab.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/_includes/scripts/misc.liquid b/_includes/scripts/misc.liquid index 86f81fa69139..07b117e46990 100644 --- a/_includes/scripts/misc.liquid +++ b/_includes/scripts/misc.liquid @@ -33,4 +33,4 @@ - \ No newline at end of file + diff --git a/assets/js/jupyter_new_tab.js b/assets/js/jupyter_new_tab.js index c7f8208a83db..4098af66edd5 100644 --- a/assets/js/jupyter_new_tab.js +++ b/assets/js/jupyter_new_tab.js @@ -15,4 +15,4 @@ $(document).ready(function () { } }); }); -}); \ No newline at end of file +});