views:

205

answers:

2

Safari 3.0.x doesn't support the document.compatMode property to detect whether the document is rendered in standards or in quirks mode. Safari 3.1 and newer do support it. How do I detect the document mode in Safari 3.0.x if document.compatMode is not available?

+1  A: 

A quick Google search results in: "HOWTO determine the document's compatibility mode"

Basically you create a div with an invalid css style that would only work in quirks mode. You then check the new div's style to see if the css was accepted. If it was accepted, the document is in quirks mode.

To paraphrase the code:

var el = document.createElement('div');
el.style.cssText = 'position:absolute;width:0;height:0;width:1';
var compatMode = el.style.width === '1px' ? 'BackCompat' : 'CSS1Compat';

I would test this for you but I can't run Safari. Please test it if you can and report the results in a comment.

brianpeiris
It works perfectly in Safari 3.0.x
Fabian Jakobs
No good. That code results "BackCompat" in IE when IE is in standards mode.
Garrett
The Google article uses Browser detection and expandos -- obviously no good.
Garrett
A: 
Garrett