Add functionality to open external links in jupyter notebooks in new tab (#2233)
See https://github.com/alshedivat/al-folio/pull/2230 --------- Co-authored-by: Scherrmann <scherrmann@bwl.uni-muenchen.de>
This commit is contained in:
parent
70ad4ceb42
commit
c1f168473f
|
|
@ -31,3 +31,6 @@
|
||||||
<script src="{{ '/assets/js/no_defer.js' | relative_url | bust_file_cache }}"></script>
|
<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/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>
|
<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>
|
||||||
|
|
|
||||||
|
|
@ -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");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue