Skip to content

Instantly share code, notes, and snippets.

@rmpel
Last active January 20, 2021 11:51
Show Gist options
  • Select an option

  • Save rmpel/cd6c3e9e66eff5bb61c41852b01c5648 to your computer and use it in GitHub Desktop.

Select an option

Save rmpel/cd6c3e9e66eff5bb61c41852b01c5648 to your computer and use it in GitHub Desktop.
Filter outbound links, external images, scripts and stylesheets with jQuery(":outbound");
(function($){
$.expr[':'].outbound = function(elem, index, match){
var att = 'nothing';
if ($(elem).is('a') || $(elem).is('link')) {
att = 'href';
}
if ($(elem).is('img') || $(elem).is('script')) {
att = 'src';
}
return ($(elem).attr(att) || "").match(/^https?:\/\//) && ! ($(elem).attr(att) || "").match(new RegExp(document.location.host.replace(/^www\./, '').replace('.', '\\.')));
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment