Posted By

jackkeller on 11/01/11


Tagged

jquery


Versions (?)

Open External Links In New Window


 / Published in: JavaScript
 

  1. $('a').each(function() {
  2.    var a = new RegExp('/' + window.location.host + '/');
  3.    if(!a.test(this.href)) {
  4.        $(this).click(function(event) {
  5.            event.preventDefault();
  6.            event.stopPropagation();
  7.            window.open(this.href, '_blank');
  8.        });
  9.    }
  10. });

Report this snippet  

You need to login to post a comment.