luke.b//blog

< back to logs after before

That works. The script is quite small:

const origin = window.location.origin
const links = Array.from(document.querySelectorAll("a"))
  .filter(a => ! a.href.includes(origin))

links
  .forEach(a => a.target = '_blank' )

console.info('external_links.js: ' + links.length + ' links converted')

This is actually the first JavaScript that I’ve used on my blog, which is mostly just a lot of different statically-generated HTML pages, and some clever CSS.