Navigation external links new tab
Aitor Rosell Torralba
Okay i created some code that would actually do this as a workaround
This goes on the head section:
<script>
var linkDetector = function() {
var arr = document.querySelectorAll('nav a')
var len = arr.length
var url = document.location.host
for (var i = 0; i < len; i++) {
if (!arr[i].href.includes(url)) {
arr[i].target = "_blank"
}
}
}
</script>
and this in the body section:
<script>
window.addEventListener('load', function() {
setTimeout(function() {
linkDetector()
}, 100)
})
</script>
Casey Colella
if you use the html or markdown editor, you can use the target="_blank" attribute of the anchor
a
tag to do that. Or you could inject javascript to automatially add this to anchor tags that have an href that match some patternAitor Rosell Torralba
Casey Colella: i meaned in the navigation menu, the one in the left, the blue one.
Casey Colella
Aitor Rosell Torralba: add this to your theme HTML Head Injection:
<script>
window.onload = function() {
for (var links = document.links, i = 0, a; a = links[i]; i++) {
if (a.host !== location.host) {
a.target = '_blank';
}
}
};
</script>
Aitor Rosell Torralba
Casey Colella: i did it myself, a little bit more targeted so this only happens whit the nav items, but thanks