views:

1517

answers:

6

Let's you have a page with a relatively strict doctype and HTML markup that's pretty close to compliant, but perhaps misses in a few silly ways that are out of your control.

How can you tell (or: what will determine) when the browser decides to go into "quirks" mode rather than use it's more standards compliant engine?

I'm looking for answers for each of the major browsers, since IE, Chrome, Safari, and Firefox will of course all handle that differently. Is one single error enough to force it or do you have some leeway?

+7  A: 

In Firefox and Opera you can determine if your browser is in "quirks mode" by checking page info.

Using document.compatMode, will tell you the mode you are in with most browsers.

Chris Ballance
+1  A: 

If you tell IE that it should be strict (via doctype) it will not change its mind halfway through the page.

jeffamaphone
+3  A: 

According to http://www.quirksmode.org/css/quirksmode.html : "The problem was that some pages written in quirks mode did have doctypes. Therefore each browser has its own list with doctypes that trigger quirks mode. See this browser comparison chart for an overview of these lists : http://hsivonen.iki.fi/doctype/"

Hope this helps

Sébastien Nussbaumer
+1  A: 

The full answer to your actual specific question of 'Is one single error enough to force it or do you have some leeway?' is that it totally depends on the error. For example,

<!-- Comment -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;

will force quirks mode in IE 6 & 7 despite not really ebing an error (they just throw a total wobbly when the very first line of the file is not a declaration). A quick list of types/quirks can be found here

Try sticking the following line in your HTML for testing (very bad javascript behavious I'm passing on here - sorry...make sure this never goes live :)

<a href="javascript:alert(document.compatMode);">What mode am I?</a>
Steerpike
+1  A: 

If I understand quirks mode correctly, a page that does not validate against its declared doctype is not enough to trigger quirks mode. It just won't display correctly.

The best resource I've found for determining how different browsers handle each doctype is here.

Bill the Lizard
+4  A: 

As you can query the render mode in JavaScript you can have a Bookmarklet which will tell you which render mode a page is using.

I found this render mode bookmarklet which works well for me:

javascript:m=(document.compatMode=='CSS1Compat')?'Standards':'Quirks';window.alert('You%20are%20in%20'%20+%20m%20+%20'%20mode.');
Dave Webb
Very useful. Thanks.
Simon P Stevens