Posted By

1man on 10/01/08


link window jquery open external

Versions (?)

Who likes this?

3 people have marked this snippet as a favorite


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(){; 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*=''])").click(function(){
  8. return false;
  9. }).attr("title", "Opens in a new window");

Report this snippet  

You need to login to post a comment.