Tianhe Gao

JS 新标签页打开外部链接

代码:

1function externalLinks() {
2  for (let c = document.getElementsByTagName("a"), a = 0; a < c.length; a++) {
3    let b = c[a];
4    b.getAttribute("href") &&
5      b.hostname !== location.hostname &&
6      (b.target = "_blank");
7  }
8}
9externalLinks();

来自:https://stackoverflow.com/a/13147238/12539782

我找了它很久,以前曾在 Sphinx 中用过。


No notes link to this note

Welcome to tell me your thoughts via "email"
UP