Open external links in a new tab

This commit is contained in:
Jorge Maroto 2018-12-10 10:52:28 +01:00
parent c3dfc88969
commit c0e1511d9c
2 changed files with 20 additions and 0 deletions

18
static/js/patoroco.js Normal file
View file

@ -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 +=
'<i class="fa fa-external-link fa-1 external-link-margin" />';
}
}
})();