Microsoft Visual Studio Versus Internet Explorer

So I'm creating a webpage using Microsoft Visual Studio. (And so far, both times I've had to write that, I managed to typo "Studio" into "Stupid," which seems to be more appropriate.)

It defaults to creating an XHTML page, and validates it in real-time. (Which is, honestly, a cool feature.)

Unfortunately, I want to support Internet Explorer, so I attempt to change it to an HTML 4.01 Strict page. No-go: Visual Studio decides it's still XHTML Transitional and starts bitching about missing items.

So apparently Microsoft Visual Studio wants to support appropriate web standards and makes it easy for developers to do so.

Unfortunately, Internet Explorer 7 still doesn't support the XHTML that Visual Studio wants to generate. So how do they fix it? By telling Internet Explorer that it's really HTML.

Sadly, there are a number of issues with sending XHTML as HTML. There's one major issue with sending XHTML as HTML: it can be invalid in strange ways.

One of the more famous code patterns on the Internet was the following, now-deprecated, method of handling old browsers:

<script language=JavaScript><!-- // hide from old browsers
// code
// --></script>

What's the problem with that? Two problems.

  1. First, XHTML doesn't allow a "language" attribute on the script tag. That makes the above invalid XHTML, although you'd never know it in a non-validating browser.
  2. Secondly, XHTML doesn't allow the "interpret the comment" thing that HTML does. So the comment will be read literally as a comment, making that tag effectively <script/> in XHTML, which is invalid because it's missing a type attribute.

So correcting that by replacing "language" with the correct "type" tag, we get:

<script type="text/javascript"><!-- // hide from old browsers
// code
// --></script>

In XHTML, the contents of the code block should not be executed. Unfortunately, this code will be executed. Visual Studio will style the contents of the script tag, despite the fact that it's in an XML comment. And since it will be sent to the browser, it will render in HTML mode that will execute the contents of the script.

There are other issues (in XHTML, document.body.tagName should be "body" while in HTML it's "BODY"), but generally, it's a bad idea to use XHTML as if it were HTML.

Unfortunately, Visual Studio will always treat HTML as XHTML, and bitch about the missing namespace.

Le Sigh.