Open External Links In New Window


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.