The Artima Developer Community
Sponsored Link

Web Buzz Forum
Serving "Valid" XHTML Strict with target="_blank"

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Douglas Clifton

Posts: 861
Nickname: dwclifton
Registered: May, 2005

Douglas Clifton is a freelance Web programmer and writer
Serving "Valid" XHTML Strict with target="_blank" Posted: Feb 18, 2006 9:37 PM
Reply to this message Reply

This post originated from an RSS feed registered with Web Buzz by Douglas Clifton.
Original Post: Serving "Valid" XHTML Strict with target="_blank"
Feed Title: blogZero
Feed URL: http://loadaveragezero.com/app/s9y/index.php?/feeds/index.rss1
Feed Description: Web Development News, Culture and Opinion
Latest Web Buzz Posts
Latest Web Buzz Posts by Douglas Clifton
Latest Posts From blogZero

Advertisement

close Question: Which of the following DTDs allow target attributes with anchor elements?

Answer: None of them.

The target attribute is designed for frames (who uses frames?)—if you want to use targets, use a Frameset or Transitional DOCTYPE.

Sadly, I am witnessing an ever growing trend with sites that serve strict document types (XHTML in particular) and insist on opening new windows from external links. Yet they still want to sport the "Valid" XHTML W3C badge on their sites.

The trick? Simple, just use a rel attribute of "external" on those anchor elements, and then dynamically alter the DOM using JavaScript to add a "_blank" target attribute.

It took me all of 5 minutes to write this little function and test it with an XHTML 1.1 document:

/* give anchors with attribute rel="external" a target attribute of "_blank" */

function external() {
 if (document.getElementsByTagName) {
  var i, a;
  a = document.getElementsByTagName('a');
  for (i in a) {
   if (a[i].getAttribute('href') && 
       a[i].getAttribute('rel') == 'external') a[i].target = '_blank';
  }
 }
}

window.onload = external;

/* external.js */

The results? The W3C Validator happily reported "This Page Is Valid XHTML 1.1!" Why? Because of course it doesn't know anything about what happens to the DOM after you've altered it with client-side scripting.

Is this old news? Probably. Do I intensely dislike people who insist on opening new browser windows just because they are under the (false) impression they will somehow retain the visitor by doing so? Yes, very much. And I happen to the think this point of view is ass backwards. Thankfully, I can use a browser like Firefox that allows me to at least redirect these links to a tab—and when I notice it happening, it usually only takes me one more visit before I mentally blacklist that site forever.

Are there times when opening a new window is warranted? Occasionally, if done with care and for the right reasons. I'm not going to get into that. Argue amongst yourselves.

Read: Serving "Valid" XHTML Strict with target="_blank"

Topic: Loads of stuff on the go Previous Topic   Next Topic Topic: Getting Things Done

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use