Sunday May 04, 2003
target="_blank" in XHTML 1.0 Strict I've always wondered how to add a target="_blank" to my XHTML 1.0 Strict pages. Thanks to this article, I now know a nice workaround.
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 <a> tag. The Transitional versions of the specifications still include it, but by definition, these specs are on the way out.
The short and sweet version is to use the "rel" attribute to your advantage.
<a href="document.html" rel="external">external link</a>
And then use this short script to key off this attribute for adding a target="_blank" (using the DOM).
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;
Throw this in an "external.js" file and add it to whatever pages you need it in.
<script type="text/javascript" src="/external.js"></script>
This LOT more work than I expected, but since it's written up in an actual article, I tend to believe that this is probably the shortest path to making this happen.
Posted in The Web
at May 04 2003, 06:13:06 AM MDT
1 Comment
Search This Site
Recent Entries
- Wine Tasting in Napa Valley
- How to build a Shot-Ski
- Bus Project Update
- Farewell to the 2011-2012 Ski Season
- Cruising around the Western Caribbean
- Spring Break!
- A Spectacular Trip to Stockholm and Madrid
- Comparing Web Frameworks and HTML5 with Play Scala at Jfokus 2012
- Play Framework 2.0 with Peter Hilton at Jfokus
- Secure JSON Services with Play Scala and SecureSocial
Posted by AJ Lincoln on January 04, 2004 at 08:10 PM MST #