mengu on web programming.

External Links in New Windows

If you are using markdown with your blog or sick and tired of adding target="_blank" to your links while creating a new post and if you just simply write the link and skip, here is my solution for you:

$(document).ready(function () {
    $('a:not([href^="http://www.mengu.net/"])').each(function(i) {
        if (!$(this).attr('target'))
        {
            $(this).attr('target', '_blank');
        }
    });
});

If you add this 8 lines of code to your header, then all the external links on your blog or web site will be opened in new window. Do not forget to include jquery too.

If you want to know why I really needed it, you can see here.

Tags:

Comments

No comments made for this post.

Leave a Response

No HTML allowed. You can use markdown.
Name*:
E-Mail* (not published):
Web site:
Response: