我知道现代浏览器通常有两种渲染模式:标准模式和怪异模式。浏览器检测标题DocType。
问题是如何在运行时检测当前页面的渲染模式。有没有Firebug工具呢?
答案 0 :(得分:22)
在IE8之前:
alert('Page was rendered in ' +
((document.compatMode == 'CSS1Compat') ? 'Standards' : 'Quirks') + ' Mode.');
对于IE8:
var vMode = document.documentMode;
var rMode = 'IE5 Quirks Mode';
if(vMode == 8){
rMode = 'IE8 Standards Mode';
} else if(vMode == 7){
rMode = 'IE7 Strict Mode';
}
alert('Rendering in: ' + rMode);
请注意,为了获得IE8新的“默认标准模式”行为的好处,您需要在IE8标准模式下进行渲染。
此模式会影响HTML + CSS 的呈现以及document.getElementById( id );
和.setAttribute( name, value );
答案 1 :(得分:1)
您还应该查看jQuerys jQuery.support。它会告诉您浏览器支持哪些标准(boxModel,不透明度等)
http://docs.jquery.com/Utilities/jQuery.support
即
jQuery.support.boxModel; //false in IE when in quirksmode, true otherwise.