Open All External Links in a New Window/Tab using jQuery

$(document).ready(function() {
  $("a[href^='http']").not("[href*='mysite.com']").attr('target','_blank');
});

... and to match two urls/domains/whatever:

$(document).ready(function() {
  $("a[href^='http']").not("[href*='mysite.com'],[href*='mysite2.com']").attr('target','_blank');
});
Tags: 

Add new comment