Snippets, xHTML

Open link in a new window using jQuery


<a href="" rel="external">Google</a>


$(document).ready(function() {
    $("a[rel=external]").attr('target', '_blank');


$(document).ready(function() {
    $('a[rel="external"]').click( function() { $(this).attr('href') );
        return false;

8 thoughts on “Open link in a new window using jQuery

  1. examples please, i can’t imagine that, and i don’t have time to try it myself
    thank you in advance

  2. Nice, but in FF 3.6.3 on Win7 it opened in same tab first example(short one).

  3. Terrific. Thank you very much for sharing. I did wonder what you were supposed to do with no target attribute allowed in XHTML.

    Further to Eugene’s comment above, the top example works fine for me.

  4. Neither works for me in FF 3.6.3

  5. $(document).ready(function() {

    can be replaced with


  6. Doesn’t work in IE9. Opens in the same window (same browser tab).

  7. Sorry, I meant it doesn’t work in IE8. I haven’t tried it in IE9 yet.

Comments are closed.