The (X)HTML strict way to open a new window

There has been a fuss on websites that don’t go through validation simply because they have a wrong way of opening a link on a new window. The old conventional way of opening a link on a new window was simply by adding an attribute like:

  1. <a href="http://example.com" target="_blank">My new window link</a>

This was both easy to remember and implement. Since the 4.0 strict specification though this is not considered valid any more. I was against that until I read the reason why this changed. Simply because the meta information an HTML document contains is related to the current window and current site. Should you want to refer to a new window it’s simply not within the scope of this page’s description. That’s why it is considered to fall within the client side to implement through Javascript for example.

I am not sure I agree with that since it doesn’t really interfere with the meaning of the meta description of the page that the current HTML does, it’s simply an easy way to do it. On the other hand, since you want the validation to be successful, the easiest way to do it is by adding a small Javascript on the link. You can do it like:

  1. <a onclick="window.open(this.href); return false;" href="http://example.com">My new window link</a>

It’s not as hard but it’s definitely not as simply as the first way. What do you prefer? Simplicity or validity? It’s really up to you but I usually go with the first…



Leave a Reply