New-Window Links in a Standards-Compliant World

Written on February 1, 2008 – 10:43 am | by Hii Hiong Ching |

Much to the chagrin of Web designers everywhere, the HTML 4.0 Strict and XHTML 1.0 Strict recommendations of the W3C no longer include the target attribute of the tag. The Transitional versions of the specifications still include it, but by definition, these specs are on the way out.

Whatever your personal feelings on the practice, the most common application for this attribute — opening a link in a new browser window with target=”_blank” — is still useful on today’s Internet. So if the standards say we shouldn’t use it, how should we go about creating new-window links, while following the latest Web standards?

You can read the original articles from here: http://www.sitepoint.com/article/standards-compliant-world/

The Complete Script

Here is the complete script. Notice the last line, which assigns the externalLinks function to the window’s onload event handler. This triggers the function when the document has finished loading.

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i

As this is the kind of script you'll want to deploy across your entire site, you should copy this code into a separate file (e.g. external.js), and then load it in every page on your site with the following code, which should appear in the tag of each document:


For these links, we set the rel attribute to external.

Before:

external link

After:

external link

So, now that we have our new-window links marked up in a standards-compliant way and javascript will cause them to actually open in a new window.

Popularity: 9% [?]

Post a Comment

About Office-it.orG

This is a site to share my knowledge, discovery and experience related to my hobby and work. Most articles on this site are related to web design, web development, graphic design, short reviews, tips and tricks. I sometimes write some about Microsoft Office Application too.

Want to subscribe?

RSS Subscribe in a reader Or, subscribe via email:
Enter your email address:  
Find entries :