JSFiddle - React, Tailwind, and code Playground
by Todd Levy
HTML
<a href="http://md.com/">MD.com</a><br />
<a href="http://doctors.md.com/">doctors.MD.com</a>
JavaScript
jQuery(function($){
filterExternalLinks();
});
function filterExternalLinks()
{
// ADD TARGET BLANK TO ANY URLS TO EXTERNAL HOSTS
// USE rel="samewindow" ON EXTERNAL LINK TO OVERRIDE
$("a").filter(function() {
return $(this).hostname && $(this).hostname !== location.hostname && $(this).attr('rel') != 'samewindow' && !this.attr('target');
}).attr('target', '_blank');
// ADD TARGET BLANK TO ANY URLS WITH rel="external"
$("a").filter(function() {
return $(this).attr('rel') == 'external';
}).attr('target', '_blank');
// ADD TARGET "doctorsite" TO ANY URLS POINTING TO doctors.md.com
$("a").filter(function() {
return $(this).attr('href').indexOf("://doctors.md.com") != -1;
}).attr('target', 'doctorsite');
}