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:

$(document).ready(function(){
$(‘.blank’).attr(‘target’,’_blank’)
$(‘.post a’).attr(‘target’,’_blank’);
});

… or if you get conflict with wordpress

var $j = jQuery.noConflict();

$j(function(){
$j(‘.blank’).attr(‘target’,’_blank’)
$j(‘.post a’).attr(‘target’,’_blank’);
});

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


Posted

in

by

Tags: