Skip to content

Instantly share code, notes, and snippets.

View martinwheeler's full-sized avatar

Martin Wheeler martinwheeler

View GitHub Profile
@martinwheeler
martinwheeler / target_blank.js
Last active September 8, 2016 09:11
Add target _blank to all URLs which are external
jQuery('a').each(function() {
var url = jQuery(this).attr('href');
var httpRegex = new RegExp('https?:\/\/', 'i');
if (url.toLowerCase().indexOf(window.location.hostname) == -1 && httpRegex.test(url)) {
jQuery(this).attr('target', '_blank');
}
});