That the target attribute is not by default allowed in valid XHTML 1.1 or XHTML 1.0 Strict continues to be a source of frustration for designers. It simply doesn't have to be. Others -- Jacques Distler and Dave Hodder, namely -- have pointed out that XHTML is designed to be modular and that it's easy to extend the specification by creating your own DTD. Jeffrey Zeldman suggests caution:
This approach is very much in the spirit of XHTML extensibility but leaves open the question of whether browsers that use DOCTYPE switching will render such a page in Standards or Quirks mode. Such browsers (IE, Mozilla/Netscape, and now Opera 7) do not download and parse DTDs; they rely on known DOCTYPE declarations stored in an internal database to determine how a page should be rendered.
Zeldman's better-safe-than-sorry response is understandable, but there's no evidence that Internet Explorer, or any other browser, will punish you for extending XHTML. In fact, there's a lot of evidence that custom DTDs are supported by the major players. Mozilla, for example, invokes Standards Mode at the sight of any unknown DOCTYPE, as well as for DOCTYPEs extended via an internal subset. (I've been using an internal subset to extend XHTML 1.1 since September 2003.) Internet Explorer, too, defaults to Standards Mode when confronted with an unknown DOCTYPE. Opera's docs don't explicitly claim similar support, but the following tests suggest identical behavior.
See for yourself:
DOCTYPE declaration. Rendered in Standards Mode by Opera 7, Internet Explorer 6, and Mozilla 1.7.DOCTYPE declaration. This document is also rendered in Standards Mode by Opera 7, Internet
Explorer 6, and Mozilla 1.7.The tests determine if extensions are invoking Quirks Mode through use of the JavaScript compatMode property, which returns BackCompat when in Quirks Mode and CSS1Compat in Standards Mode, and the CSS box model, which behaves differently in Quirks and Standards Modes.
Extending via an external subset of the declaration is convenient (since you don't have to create your own DTD), but this method leaves a short string of characters -- the end of the subset, in fact -- at the top of pages served as text/html. Documents served as application/xhtml+xml do not have this problem. As such, Jacques's method is the best solution for most cases.
The test documents are served as text/html for two reasons:
In other words, serving XHTML as application/xhtml+xml to Gecko browsers gets you Standards Mode every time, as does serving a custom DTD to any browser. There's no indication that extending XHTML will rain on your standards parade.
Update: The Mozilla "View Page Info" tool (Ctrl+I) also tells whether a particular page is in Standards Mode or Quirks Mode. I wasn't aware of this feature when I first wrote these tests.
I should have said, "Jacques's method is the best solution for most cases, if you're using XHTML 1.0 Strict."
Don't copy Jacques's method directly if you plan on serving your documents as
text/html. You shouldn't be sending XHTML astext/htmlin the first place, but you definitely shouldn't if you're using XHTML 1.1.And keep in mind that
text/htmlis the only thing keeping you from the other solutions, anyway. You won't get the extra string of characters if you're serving your documents properly, asaplication/xhtml+xml. And, you don't have to worry about Quirks Mode if you serve asaplication/xhtml+xml; the browsers that support it always invoke Standards Mode for documents served this way. It's another benefit of doing things correctly.I have tried Number 2:
An XHTML 1.1 document extended via an internal subset of the DOCTYPE declaration.
No matter what I do, both Internet Explorer and Firefox display ]> at the top of the document.
I have also placed <meta http-equiv="Content-type" content="application/xhtml+xml; charset=UTF-8" /> within the html code.
I assume IE would display the characters ]> but Firefox?
What is the deal?
I have tried Number 2:
An XHTML 1.1 document extended via an internal subset of the DOCTYPE declaration.
No matter what I do, both Internet Explorer and Firefox display ]> at the top of the document.
I have also placed <meta http-equiv="Content-type" content="application/xhtml+xml; charset=UTF-8" /> within the html code.
I assume IE would display the characters ]> but Firefox?
What is the deal?
Sorry for being so late to reply. I missed these comments until now.
To be clear, Mozilla will not display the
]>if the document is served asapplication/xhtml+xml; the file extension has nothing to do with it. Daniel's point is well-taken, however; you will need to configure your server to send static files with the proper MIME type;meta http-equivalone won't cut it.