Aprire i link esterni in una nuova finestra è un'operazione molto semplice in JavaScript.
La soluzione è la seguente.
'use strict';
const externalLinks = () => {
const links = document.querySelectorAll('a[href^="http"]');
if(links.length > 0) {
links.forEach(link => {
let href = link.getAttribute('href');
if(!href.includes(location.host)) {
link.setAttribute('target', '_blank');
}
});
}
};