Posted By

1man on 10/01/08


Tagged

link window jquery open external


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

basicmagic
bostonbasso
Eystein


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');
  5. //Similar to the first, only using your domain name
  6. $("a:not([href*='yourdomainnamehere.com'])").click(function(){
  7. window.open(this.href);
  8. return false;
  9. }).attr("title", "Opens in a new window");

Report this snippet  

You need to login to post a comment.