Created
August 9, 2013 10:10
-
-
Save Crydust/6192601 to your computer and use it in GitHub Desktop.
This very imperfect code will give you a fighting chance to determine the actual document mode msie is using. Also see Testing sites with Browser Mode vs. Doc Mode
http://blogs.msdn.com/b/ie/archive/2010/10/19/testing-sites-with-browser-mode-vs-doc-mode.aspx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script>var ccMsie = -1;</script> | |
<!--[if gte IE 6]><script>ccMsie = 6;</script><![endif]--> | |
<!--[if gte IE 7]><script>ccMsie = 7;</script><![endif]--> | |
<!--[if gte IE 8]><script>ccMsie = 8;</script><![endif]--> | |
<!--[if gte IE 9]><script>ccMsie = 9;</script><![endif]--> | |
<script>/*@cc_on @if (@_jscript_version == 10) ccMsie = 10; @end @*/</script> | |
<script> | |
(function(){ | |
function readVersion(s) { | |
var ua = navigator.userAgent; | |
var index = ua.indexOf(s); | |
if (index == -1) { | |
return -1; | |
} | |
return parseFloat(ua.substring(index + s.length + 1)); | |
} | |
var msie = readVersion('MSIE'); | |
var compatMode = document.compatMode; | |
var trident = readVersion('Trident'); | |
var documentMode = document.documentMode || -1; | |
var browserModeString = 'Unknown'; | |
var documentModeString = 'Unknown'; | |
if (compatMode === 'CSS1Compat') { | |
if (msie === documentMode && (trident === -1 || msie === trident + 4)) { | |
browserModeString = 'IE' + documentMode; | |
} else if (documentMode === trident + 4) { | |
browserModeString = 'IE' + documentMode + ' Compat View'; | |
} else if (msie === trident + 4 || (msie === 7 && trident === -1)) { | |
browserModeString = 'IE' + msie; | |
} | |
if (documentMode != -1 && (documentMode != msie || documentMode === 7)) { | |
documentModeString = 'IE' + documentMode + ' Standards'; | |
} else { | |
documentModeString = 'Standards'; | |
} | |
} else { | |
if (msie !== trident + 4 && !(msie === 7 && trident === -1)) { | |
browserModeString = 'IE' + (trident + 4) + ' Compat View'; | |
} else { | |
browserModeString = 'IE' + msie; | |
} | |
if (documentMode === 5) { | |
documentModeString = 'IE5 Quirks'; | |
} else { | |
documentModeString = 'Quirks'; | |
} | |
} | |
document.write(['<div style="position:absolute;top:50px;left:50px;background:#fff;color:#000;border:3px solid #000;padding:10px;font-size:16px;z-index:1000;">', | |
'<pre>', | |
'<b>Raw data</b>\n', | |
'ccMsie = ', ccMsie, '\n', | |
'msie = ', msie, '\n', | |
'compatMode = ', compatMode, '\n', | |
'trident = ', trident, '\n', | |
'documentMode = ', documentMode, '\n', | |
'\n', | |
'<b>Interpretation</b>', '\n', | |
'Browser Mode: ', browserModeString, '\n', | |
'Document Mode: ', documentModeString, '\n', | |
'\n', | |
'<b>Box model test</b>', | |
'</pre>', | |
'<div style="background:#000;width:100px;height:10px;"></div>', | |
'<div style="background:#000;border-left:10px solid #333;border-right:10px solid #333;width:80px;height:10px;"></div>', | |
'<div style="background:#333;border-left:10px solid #666;border-right:10px solid #666;padding:0 10px;width:60px;height:10px;"><div style="background:#000;height:10px;"></div></div>', | |
'</div>'].join('')); | |
}()); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment