|
XHTML has been around long enough now that most people have heard of it, and most web developers know what to do to ensure their code produces valid XHTML. You will often see little notes in page footers claiming "Valid XHTML" or similar, and often enough, it even is valid XHTML. Unfortunately, however, the overwhelming majority of valid XHTML web pages might as well not be, because the browser has no idea that they are, and treats them as the bog-standard tag soup anyway.
The reason? The MIME type specified in the HTTP Content-Type header claims that the page is "text/html" or similar, which is what the browser pays attention to, not the DOCTYPE element. The culprit? Microsoft (obviously). Internet Explorer (even the new version 8) can't quite handle XHTML properly and if you try serving it XHTML documents with the correct MIME type (application/xhtml+xml), it will simply offer to download the page for you. But if you're sick of waiting for Microsoft to play the game (that being either co-operation or catch-up, depending on your political views) and you want to start using XHTML-based technologies (stuff like XForms, SVG, RDFa and MathML), serving XHTML for what it actually is works just fine on "all Mozilla-based browsers, such as Mozilla, Netscape 5 and higher, Galeon and Firefox, as well as Opera, Amaya, Camino, Chimera, DocZilla, iCab, Safari, and all browsers on mobile phones that accept WAP2. In fact, any modern browser." —W3C FAQ And if you just want to serve up the correct MIME type only to browsers that understand it, there's always the HTTP_ACCEPT header. Basically, you can just check this header that is sent by the browser, to see what content types it supports, then set the Content-Type header appropriately in code. Of course, this doesn't help much if you're actually trying to use XHTML for something - it still won't work in IE, but not everybody has to care; for example, in situations where you can control the browser environment (as with some corporate intranets) or if your primary audience is Linux users, you might be happy to inform IE users that they need a modern, standards-compliant browser, or point them towards the various IE plugins and hacks around that can be used to provide some of the missing support (I might compile a directory of these when I have more time). Anyway, since I'm going to be building stuff to add semantic markup to Joomla! content, one of the main prerequisites is XHTML. And as standard, Joomla! won't serve pages as XHTML, unless you've configured your web server to do it, which is probably not a good idea - for starters, the Joomla! Administrator (and certain parts of the front-end that use forms) won't work as XHTML. One of the main reasons for this is that Joomla! uses an old DOM Level 0 means of accessing the element named adminForm (document.adminForm) in pretty much all of it's Javascript, which won't work with the XML DOM you get with genuine XHTML documents. There are lots of other places where XHTML is broken in Joomla! (in a few cases it doesn't even output well-formed XML) but most of these are in the administration back-end. It's relatively easy to get the front-end working fully as XHTML if you're not doing much more than publishing content using the core components and I'll post more details on this when have time. But for now, I just wanted an easy way to switch XHTML on or off, for development purposes. So I've built a simple little plugin for Joomla! that lets you do just that. Once installed and enabled, all it will do is check for browser support via HTTP_ACCEPT, and change the Content-Type header where possible. It doesn't (yet) change the meta tag for the content type, or anything else that might be useful or necessary, but it's a place to start, and I'm making it available here in the hope that somebody either finds it useful for what it already is, or improves it for me first :)
Attachments:
plgSystemXHTML-0.2.zip | [An updated version that sets the MIME type and charset through JDocument methods in the onAfterDispatch event.] | 2 Kb |
plgSystemXHTML.zip | [Joomla! System Plugin For XHTML] | 2 Kb |
|