JS 新标签页打开外部链接

代码:

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 中用过。

欢迎通过「邮件」或者点击「这里」告诉我你的想法
Welcome to tell me your thoughts via "email" or click "here"