From c0e1511d9c2f5fd6f875c0640f12e97237148766 Mon Sep 17 00:00:00 2001 From: Jorge Maroto Date: Mon, 10 Dec 2018 10:52:28 +0100 Subject: [PATCH] Open external links in a new tab --- static/js/patoroco.js | 18 ++++++++++++++++++ templates/base.html | 2 ++ 2 files changed, 20 insertions(+) create mode 100644 static/js/patoroco.js diff --git a/static/js/patoroco.js b/static/js/patoroco.js new file mode 100644 index 0000000..4a2c162 --- /dev/null +++ b/static/js/patoroco.js @@ -0,0 +1,18 @@ +/* +Open external links in a new tab. +Copied from: http://mitchbarry.com/handling-external-links/ +*/ +(function() { + var hostname = window.location.hostname; + var new_tab = true; + var set_icon = true; + for (var links = document.links, i = 0, a; a = links[i]; i++) { + if (a.hostname !== hostname) { + if (new_tab) + a.target = '_blank'; + if (set_icon) + a.innerHTML += + ''; + } + } +})(); \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index cbbea97..7e2392f 100644 --- a/templates/base.html +++ b/templates/base.html @@ -205,5 +205,7 @@ {% if GITHUB_CORNER_URL %} {% include 'partial/github.html' %} {% endif %} + +