XHTML 1.0 Strict Valid target _blank

I always like to use XHTML 1.0 Strict on my projects (Update: because I had problems in the past with XHTML 1.1) , but a lot of times you want to open the links in new window to keep the visitor continue reading your site/article and the use of target=_blank is necessary.

I use one simple trick with javascript (jQuery):

  1. You can mark all the links you want to open in new window with class=”blank” and then call one javascript line: $(‘.blank’).attr(‘target’,’_blank’);
  2. You may want to open all post links in new window, you put your content in <div class=”post”> and call in javascript: $(‘.post a’).attr(‘target’,’_blank’);

In wordpress is really easy because it has jQuery enabled so you just have to make on js file with following code:

$(‘.post a’).attr(‘target’,’_blank’);

… or if you get conflict with wordpress

var $j = jQuery.noConflict();

$j(‘.post a’).attr(‘target’,’_blank’);

I used both class and .post techniques in EDUKID ( Example: Jucarii Beados )

3 thoughts on “XHTML 1.0 Strict Valid target _blank”

  1. Two questions:
    1) Why XHTML 1.0 strict? Why not transitional or even 1.1 ?
    2) A less intrusive method that i use on my blog:

    $(‘a[href^=http]:not([href*=iamntz.com])’).attr(‘target’, ‘_blank’);

    Every external link is opened in a _blank window.

  2. 1) I had problems in the past with 1.1 with diffrent browsers and I never tried it since 🙂
    2) your method is ok if you use absolute paths for url (starting with http://… ). Also, I don’t like all external links to be opened in new window, just the ones that are in middle of articles. I don’t mind user leaving my site, I just don’t want to make him frustrated to open manualy in new window.

  3. If you use it on wordpress blogs, all links are absolute unless you write by yourself.

    However, any relative links will open in the same window 🙂

    But if you really want to specify a class name, you can do this way:

    $(‘a[href^=http]:not([href*=iamntz.com]):not(.self)’).add(‘.blank’).attr(‘target’, ‘_blank’);

    Have no idea if it works 😀

    If you ask me, every link (internal or external) should open in the very same window. You don’t have to override the user choice. However, because most of my readers ASKED me to open links in new window, i did this trick 🙂

    Anyhow, in order to reduce bounce rate and keep your visitors on your site for a longer time, every external link MUST open in a new window.

Comments are closed.