Switching from Transitional to Strict

September 25th, 2006

xhtml strict
I’ve been using XHTML Transitional for while and been happily validating my code on the w3c website until I heard a podcast from Dustin Diaz. Dustin said he prefered HTML strict to XHTML Transitional.
Looking into the reason I used Transitional - because it’s a bit more forgiving - I realised that I should try and make the move to xhtml strict. Looking at my code I was pretty confident that switching to Strict would be fairly painless.

Overall I have to say it wasn’t too much of a headache but the 2 attributes I had to abandon were:
target=
border=
While finding alternatives for some depreciated tags like STRIKE is easy as replacing it with another (in this case DEL) others were more tricky.I used the target=”_blank” to open links to external sites in a new window. As STRICT won’t even negotiate :) the only solution I was able to find was to use Javascript. Although I have nothing against Javascript I hate using it for such a simple thing, especially when it is not needed for any other tasks on the site.

Fortunately the script is short and will still allow users to click the link if they have javascript disabled.
This script has been borrowed from a post on xoops.org but the poster isn’t sure who the orignal author is

While most sites will suggest putting this in the head of the page I recommend creating a seperate js file. This file then can be linked to from any page on any site to load the script. It can be seen in the head of the About Us page on my current project mypetsite.co.uk

function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i&ltanchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("href") &&
anchor.getAttribute("rel") == "external")
anchor.target = "_blank";
}
}
window.onload = externalLinks;

You will also need to modify the body tag:

 < body onload="externalLinks();" > 

Finally indicate which links you want to be opened in a new window/tab. Replace any target=_blank with:

rel="external"

Not a simple change and I could hardly call it better for the user but it validates in XHTML STRICT.

A voyage into Javascript wasn’t required for replacing the border=”0″. I used this on some images that some browsers give an ugly blue border when the image used as a link. This is a simple matter of css.

As I dont use a border on any of my images I inserted:

img {
border-style=”hidden”;
border=”0″;
}

It is very unlikely that both css commands are needed but I like to make sure I kill that horrible border dead. For more specific border blasting create a class called noborder or similar and then assign it to the offending images.

On the positive side it wasn’t too difficult to make the switch over and it feels good to be using a more semantic code.

Have your say?

Comments welcome - you don't have to agree :)

2 Responses to “Switching from Transitional to Strict”

  1. Jessica on April 4, 2007 2:13 am

    This site rocks! Keep up that excellent work! http://allaboutheadsets.blogspot.com/

  2. Jewellery wholesale on May 6, 2007 10:34 am

    Wonderful articles. Thanks for such a nice information http://engagementring.blogtopia.com/

Name (required)

Email (required)

Website


Speak your mind

Trackback URL | Comments RSS

    About

    Although originally designed to document my work and new web development tricks I learnt it has expanded to cover tech and news that I find interesting so in addition to tutorials and interviews expect to see product reviews and tech news too. If you enjoy please comment. David

    Blogroll
    • Adele Kirby - Freelance Writer and most chipper/perky person alive
    • Alex Pullin - Freelance Tech Writer and former PR queen
    • Display: Block - Blog of fellow developer Savell Martin
    • Molly E. Holzschlag - Web standards advocate and Genious
    • Nate Laxon - Funny guy and music guru
    • Paul Boag - Helping website owners and promoting webstandards. The King of Web Design Podcasts
    • Poached Online - news/current affairs/political comment: no eggs
    • Tale of 2 Blogs - Blog about my other blogs
    Admin
  • From Display:Block
    • SpringWidgets
      RSS Reader
      This widget is the staple of our platform. Read all your feeds right here with this one widget - Supported feeds are OPML, RSS, RDF, ATOM. Watch your favorite Podcast in the embedded Video Player on the Desktop or publish your own video playlist to your site for others to view!
      Visit the Widget Gallery