The W3C’s online markup checker doesn’t throw errors on this yet, but URI’s are not supposed to have spaces in them, at least not in XHTML Strict. So code like this:
<a href="javascript:void window.open('#/email.php?p=#', 'etc.');">
...</a>
is no good. For those unpracticed in HTML, the URI is everything in the “href” part of the a tag, and there is a space between “javascript:void” and “window.open.” This error came to my attention thanks to Marc Gueury’s HTML Vaildator extension for Firefox, which uses the HTML Tidy program to check for web standards compliance.
These javascript-infused links are used for the E-mail and Print Post features, and the javascript causes the link to open in a new window/tab instead of the current window. Now, the classic, standards compliant way to open content in a new window is:
<a href="#"
onclick="window.open(this.href); return false;"
onkeypress="window.open(this.href); return false;">...</a>
This way uses mouse and keyboard event handlers to fire off window.open, instead of bundling it into the URI itself, spaces and all. This is more accessable for those who have javascript turned off. For those people, the link will now execute – before, they got nada – it just won’t open in a new window. So I changed the code in my template to this:
<a href="<?php bloginfo('stylesheet_directory'); ?>/email.php?p=<?php the_ID(); ?>" onclick="window.open(this.href, 'etc.'); return false;" onkeypress="window.open(this.href, 'etc.'); return false;">...</a>
for both the E-mail and Print functions (with appropriate changes for the latter) and volia, the blog is validating again/for real!