Last active
January 20, 2021 11:51
-
-
Save rmpel/cd6c3e9e66eff5bb61c41852b01c5648 to your computer and use it in GitHub Desktop.
Filter outbound links, external images, scripts and stylesheets with jQuery(":outbound");
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
| (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