From 9c1985e01e2fac0b87c99339f888f2cb1e369aa9 Mon Sep 17 00:00:00 2001 From: Noah Date: Fri, 26 Aug 2022 20:38:17 -0700 Subject: [PATCH] Make external links open in new tabs --- web/static/js/bulma.js | 10 ++++++++++ web/templates/forum/new_post.html | 12 ------------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/web/static/js/bulma.js b/web/static/js/bulma.js index f116d2e..138efda 100644 --- a/web/static/js/bulma.js +++ b/web/static/js/bulma.js @@ -1,6 +1,16 @@ // Hamburger menu script for mobile. document.addEventListener('DOMContentLoaded', () => { + // Make all off-site hyperlinks open in a new tab. + (document.querySelectorAll("a") || []).forEach(node => { + let href = node.attributes.href; + if (href === undefined) return; + href = href.textContent; + if (href.indexOf("http:") === 0 || href.indexOf("https:") === 0) { + node.target = "_blank"; + } + }); + // Hamburger menu script. (function() { // Get all "navbar-burger" elements diff --git a/web/templates/forum/new_post.html b/web/templates/forum/new_post.html index 3425f50..3b65670 100644 --- a/web/templates/forum/new_post.html +++ b/web/templates/forum/new_post.html @@ -145,16 +145,4 @@ - - {{end}} \ No newline at end of file