Forest Blog and XHTML 1.0 Strict validation

When writing a new blog article or page (using TinyMCE), if you add a link which opens on a new window, it adds the invalid target="_blank" rather than rel="external". This causes any page containing these links to fail the W3C Markup Validation Service check.

To solve this, it was necessary to modify a couple of the core blog files.

First I needed to remove the target attribute "_blank" and replace it with class="external" so, in the file: Includes/Tiny/themes/advanced/jscripts/link.js, after line 65, I added:

// added
if (target == '_blank'){
target = '';
if(style_class == ''){
style_class = 'external';
}
else {
style_class = 'external ' + style_class;
}
}
// end added

This now adds the class "external" to links when "Open link in a new window" is selected. If a class is also selected, it adds the class "external" and a space before the selected class.

The existing 'new windows' links in the sidebar and foot of the blog currently use javascript to add the target attribute "_blank" to any anchor with an href attribute and a rel attribute of "external".

To get the new method to work, I needed to change this so that any anchor with an href attribute and the class "external" would also open a new window.

In the file Includes/inc-javascript.js, after line 38 I added:

// added
if (anchor.getAttribute("href") && anchor.className.indexOf("external") == 0)
{
anchor.target = "_blank";
}
// end added

This method works for all four possible scenarios:

  • Open the link in the same window with no added class style
  • Open the link in the same window with an added class style
  • Open the link in a new window with no added class style
  • Open the link in a new window with an added class style

Update

After enabling comments on the site, I discovered another couple of validation failures in the two instances of the comments form on the page default.asp

To rectify them I added the rows and cols attributes to the textarea tags and then wrapped all the form fields in fieldset tags.