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" />';
}
}
})();

View file

@ -205,5 +205,7 @@
{% if GITHUB_CORNER_URL %} {% if GITHUB_CORNER_URL %}
{% include 'partial/github.html' %} {% include 'partial/github.html' %}
{% endif %} {% endif %}
<script type="text/javascript" src="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/js/patoroco.js" async="async"></script>
</body> </body>
</html> </html>