代码:
function externalLinks() {
for (let c = document.getElementsByTagName("a"), a = 0; a < c.length; a++) {
let b = c[a];
b.getAttribute("href") &&
b.hostname !== location.hostname &&
(b.target = "_blank");
}
}
externalLinks();
来自:https://stackoverflow.com/a/13147238/12539782
我找了它很久,以前曾在 Sphinx 中用过。