...the target attribute is NOT deprecated anymore in HTML5...
While this is true today HTML5 is not a specification as of yet. The status of the W3C is at the draft stage which is stated in the STATUS section of the Draft copy of the spec. Here is a line from the document:
This is a work in progress! This document is changing on a daily if not hourly basis in response to comments and as a general part of its development process.
I will await the completion of the spec and its recommendations prior to any changes. As it is already, most people don’t fully get that HTML4.01 is the latest version of HTML not XHTML which is HTML as XML application.
@flosoft
My technique (based on Kevin Yank’s) uses the rel attribute and a class name within the URL:
i.e.
<a href="http://www.example-website.com/" rel="external" class="external">Example Website</a>
The javascript that you can either add to the top of your templates or as a chunk is as follows:
function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("href") &&
anchor.getAttribute("rel") == "external")
anchor.target = "_blank";
}
}
window.onload = externalLinks;
That code will tell the browser that the URL has a target="_blank" but since it is as a result of DOM and not HTML it will validate.
For me the big thing is in adding the class="external" which will allow me to style the link to distinguish it from in-line document links. What I typically do is place a symbolic background image (in a padded space at the right of the A element) to denote an external link. As well in the title attribute I tell people that the link will open in a new window.
Hope this helps.
Jay