Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added open-external-links.js to open external links in new tab #7540

18 changes: 18 additions & 0 deletions source/_static/js/open-external-links.js
Original file line number Diff line number Diff line change
@@ -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');
}
}
});
1 change: 1 addition & 0 deletions source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down