Setting up external links for my blogging platform

I want those pesky external links loading in a new window/tab!

Previous Post

I was looking to see about loading some external links in a new window for some third-party links, and noticed it wasn't available via the link mechanisms.

A quick search showed that using a simple JS snippet made all the difference. Loading it in the header was too soon, so putting it in the footer was the correct droid. Now I just append ?xgtab=true to the URLs in question and the script takes care of the target appending to the <a href> tag.

<script>
  // any tags we add a query param of xgtab will open in new window/tab
document.querySelectorAll("a[href*='?xgtab=true']").forEach(link => {
  link.setAttribute("target", "moredetail");
});
</script>