jQuery: Open links in external window


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

Better than previous version. You don't have to mark up your links with 'rel=external'.


Copy this code and paste it in your HTML
  1. jQuery('a[href^=h]').each(function(){
  2. if (this.hostname !== location.hostname) {
  3. jQuery(this).attr({
  4. target: "_blank",
  5. title: this.href + " (External link, click to open in a new window)"
  6. });
  7. }
  8. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.