How to detect quirks mode in Safari 3.0.x?
A quick Google Search results in: "HOWTO defines document compatibility mode"
Basically you are building div
with invalid CSS style that will only work in quirks mode. Then you check the new style div
to see if the css is accepted. If accepted, the document is in quirks mode.
To rephrase 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 cannot get Safari running. Please check it out if you can and report the results in the comment.
source to share
Most newer browsers have compatMode
, but some older browsers don't. Such browsers include Mac IE and older WebKits such as Safari 2 on the desktop and many Nokia phones.
If document.compatMode
exists, then check that this value is not "BackCompat"
. If so, the document is in standard mode. This gives an early result for IE.
Otherwise it doesn't document.compatMode
, and so it's an older browser that can support standards mode rendering, but just doesn't have the property compatMode
.
If you width
specify a width for an element that has a numeric value for , the document is not in standard mode.
You can use if - else
it if you find it more readable; or, alternatively, use a triple purpose.
/ * 2010-06-26 Garrett Smith - BSD License * / function isQuirksMode (doc) { doc = doc || document; var compatMode = doc.compatMode, testStyle, IS_STANDARDS_MODE = compatMode? compatMode! = "BackCompat": doc.createElement && ((testStyle = doc.createElement ("p"). style) .width = "1", ! testStyle.width); return! IS_STANDARDS_MODE; }
This applies to older versions of Webkit that may exist on mobile devices such as Nokias in countries around the world.
It will return true in IE5.5 and below. Checking inference for existence for createElement
will fail in any browser that has a createElement that is broken (Opera 5, I assume).
Avoid using this function to draw general conclusions; always try to be as specific as possible.
source to share