We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

1man on 10/01/08


Tagged

link window jquery open external


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

basicmagic


jQuery open external link in new window


Published in: JavaScript 


Two different ways to open an external link (ones that start in http) in a new window. I know this isn't a great thing to do, but some clients need to have it.

  1. //Grab the href, open it in a window and cancel the click action
  2. $("a[@href^='http']").click(function(){window.open(this.href); return false;});
  3. //Add target = blant to the external link
  4. $("a[@href^='http']").attr('target','_blank');

Report this snippet 

You need to login to post a comment.