如何检测当前页面的浏览器渲染模式?

时间:2009-03-08 04:41:43

标签: javascript browser render standards mode

我知道现代浏览器通常有两种渲染模式:标准模式和怪异模式。浏览器检测标题DocType。

问题是如何在运行时检测当前页面的渲染模式。有没有Firebug工具呢?

2 个答案:

答案 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 );

等JavaScript 方法的修复

答案 1 :(得分:1)

您还应该查看jQuerys jQuery.support。它会告诉您浏览器支持哪些标准(boxModel,不透明度等)

http://docs.jquery.com/Utilities/jQuery.support

jQuery.support.boxModel; //false in IE when in quirksmode, true otherwise.