In HTML 4.01 Strict and XHTML 1.0 Strict, the Strict DTD doesn't support the target="_blank" attribute that causes a link to open a new browser window. You do have a couple of options, however, if you want a link to open a new browser window. The first option is to use a Transitional DTD, but we're using Strict DTDs in this course. The other option, then, is to use some JavaScript.
If you need just one or two links to perform this behavior, consider using the following script directly within an <a href> link, replacing the URL with the URL to which you're linking:
<a href="http://www.domain.com" onclick="java_script_:this.target='_blank';">
If you need several links to perform this behavior, then you should place some JavaScript within the <head> section and set the links up a bit differently.
In the <head> section, type or copy and paste the following after the <title> element:
<script type="text/javascript">
<!-- Hide script from old browsers
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;
//End hiding script from old browsers -->
</script>
Within the <a> element for the link, for each link you want to open a new browser window, type the link below, replacing the URL with the URL to which you're linking:
<a href="http://www.domain.com" rel="external">
The information in this document comes from the book 250 HTML and Web Design Secrets by Molly Holzschlag. The book is available at most bookstores and online. (Buy.com has the book for a decent price.)