diff --git a/source/_static/js/open-external-links.js b/source/_static/js/open-external-links.js new file mode 100644 index 00000000000..083cd2c1ed1 --- /dev/null +++ b/source/_static/js/open-external-links.js @@ -0,0 +1,18 @@ +/* +This script ensures that all external links (those with the 'external' class) +open in a new tab or window by setting their 'target' attribute to '_blank'. +*/ +document.addEventListener("DOMContentLoaded", function() { + // Select all anchor tags with the 'external' class + var links = document.querySelectorAll('a'); + for (var i = 0; i < links.length; i++) { + var link = links[i]; + // Check if the link has the 'external' class + var isExternal = link.classList.contains('external'); + if (isExternal) { + // If it's an external link, set the 'target' attribute to '_blank' + // This makes the link open in a new tab/window when clicked + link.setAttribute('target', '_blank'); + } + } +}); diff --git a/source/conf.py b/source/conf.py index ff7b67b5c82..23e27355367 100644 --- a/source/conf.py +++ b/source/conf.py @@ -3849,6 +3849,7 @@ def setup(_: Sphinx): "js/jquery.js", "js/thermometer.js", "js/myscript-v1.js", + "js/open-external-links.js", ] # The name of an image file, relative to the configuration directory, to use as favicon of the docs. This file should