New Windows, New Standards 0 Comments
All of the sites I code nowadays conform to the XHTML 1.0 Strict doctype declaration (or DTD). Except this site since, by default, WordPress uses the XHTML 1.0 Transitional DTD. In olden days people would quite regularly use target="_blank" in their anchor tags to launch a URL in a new window. Sadly, the “target” attribute is no longer supported under the strict XHTML 1.0 doctype and will throw an error when attempting to validate your page.
Googling for a standards-compliant alternative results in far too many options. Here’s the easiest and cleanest solution I’ve found:
<a href="some-url.html" onclick="window.open(this.href); return false;">Your Link</a>Extremely compact and efficient.
While we’re on the topic, don’t validate this blog. It has 32 errors and 11 warnings, according to the W3C. No, this isn’t one of those “do as I say, not as I do” copouts. I plan to try and eliminate all errors and will even write a post about the process since, IMHO, validating your site is one of the most important things you should do before launching it.