Forked from wpscholar/jquery.external-links-new-window.js
Created
September 20, 2017 23:28
-
-
Save jimboobrien/0e78607f30fb60ada769b841acc040bb to your computer and use it in GitHub Desktop.
Open all external links in a new window
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Open all external links in a new window | |
*/ | |
jQuery(document).ready(function($) { | |
$('a').not('[href*="mailto:"]').each(function () { | |
var isInternalLink = new RegExp('/' + window.location.host + '/'); | |
if ( ! isInternalLink.test(this.href) ) { | |
$(this).attr('target', '_blank'); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment