Saturday, July 4, 2009

IE Friendly Non-Compliant Code that Still Validates

I was working on a webpage recently, and as usual, IE was the only browser giving me fits. I used an object tag to embed a video player, and IE wasn't rendering it. So, to get around this problem, I used IE's conditional comments. This is a very common reaction, but most people I've seen online jump through all kinds of hoops to provide an object tag that works in IE and a different one for everyone else. I think it's ridiculous to do so much work for such a crappy browser, so I decided to use an iframe for IE and an object for everyone else. Since the iframe is hidden in the conditional comments, the markup validates, since the only real markup not hidden is the web standards compliant object tag. If IE refuses to get with web standards, why should we try to write compliant code for it? Since the conditionals hide all the non-compliant IE code in the comments, they don't interfere with validation. Here is my code below:

/* This code gives an iframe for all IE. This code is commented out and not read in validation */

/* This code is NOT commented out, and is what all browsers that aren't IE will see, and is read in validation. This code should be compliant. */

No comments: