Jquery function to open external links in new tab

Photo by Greg Rakozy on Unsplash
//Open external links in a new tab
jQuery('a').not('[href*="mailto:"]').each(function () {
    var isInternalLink = new RegExp('/' + window.location.host + '/');
    if (!isInternalLink.test(this.href)) {
        jQuery(this).attr('target', '_blank');
    }
});