I need to add a jQuery check that will launch any links across my site to external websites. How can I do the following:
Look for any anchor links that do not contain “xyz” in the hostname. For example:
http://xyz.comhttp://asfasdfadsfadsf.xyz.com
It must ignore any links that contain xyz after the hostname though:
http://someothersite.com/xyz
$('a[href^="http://%xyz%"]').filter(function() { return this.hostname && this.hostname !== location.hostname; }).attr('target', '_blank');
See this demo.
JSHint Example: