Page is a not externally linkable
- Code, Content, and Presentation
-- CSS
---- whitespace before Doctype and Quirks Mode


coopster - 9:21 pm on Apr 16, 2008 (gmt 0)


Me neither.. I just read somewhere today that whitespace won't trigger Quirks if indeed it is really whitespace - I don't understand that?

I am assuming the person that wrote that was referring to whitespace as defined in the RFC, linear white space (LWS) which is carriage return, linefeed, space, and horizontal-tab.

CR       = <US-ASCII CR, carriage return (13)> 
LF = <US-ASCII LF, linefeed (10)>
SP = <US-ASCII SP, space (32)>
HT = <US-ASCII HT, horizontal-tab (9)>

I can have any of these whitespace characters ahead of my DOCTYPE and remain in standards mode with both MSIE6 and Mozilla. Perhaps they are referring to the other "whitespace" characters, such as control characters? I just inserted a <US-ASCII BS, backspace (8)> character before the DOCTYPE and it threw MSIE into quirks mode. Mozilla remained in standards mode. I tried the ESC character as well with the same results.

For the sake of this discussion, consider the response as being either the header fields or the message body, which are separated by the extra CRLF as mentioned earlier. I think if you are considering what throws quirks mode you may have to focus on the message body itself. It seems as though any LWS is fine in the message body and doesn't trigger quirks mode, at least not in today's browser. However, you start throwing in control characters and that is another story.

In regards to server-side technology, yes, I imagine either a failing interpreter or a poor developer could throw you into quirks mode unexpectedly. I have never seen the PHP interpreter do this on it's own, but I as the programmer can indeed invoke quirks mode by inserting those characters in the message body. Take the following example, append this to the front of your example, SuzyUK, and save the file with a .php extension so your server parses it as PHP:

<?php print str_repeat [php.net]("\r\n", 10); ?> 
<p>Which Mode?</p>
<h2>
<script type="text/javascript">
mode = document.compatMode;
document.write(mode);
</script>
</h2>
<hr>
<ul><li>BackCompat = Quirks Mode</li>
<li>CSS1Compat = Standards Compliance Mode</li></ul>

That single line of PHP will write out 10 CRLF and neither browser will go into quirks mode. However, replace that line of PHP with this line which prints out a single backspace character and MSIE6 will indeed go into quirks mode.
<?php print chr [php.net](27); ?>

To summarize, I think malformed header fields would cause issues well before quirks mode might be invoked. I don't have the time to test the theory right now but if somebody else could ...


Thread source:: http://www.webmasterworld.com/css/3623733.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com