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

时间:2022-11-19 09:31:59

I know that modern browsers generally have two render mode: standard mode and quirk mode. The browser detects the heading DocType.

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

The question is how to detect render mode of current page at runtime. Is there any Firebug tool to do that?

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

2 个解决方案

#1


Before IE8:

alert('Page was rendered in ' +
  ((document.compatMode == 'CSS1Compat') ? 'Standards' : 'Quirks') + ' Mode.');

For 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);

Be aware that to gain the benifits of IE8's new "standards mode by default" behavior you'll need to be rendering in IE8 Standards Mode.

请注意,要获得IE8新的“默认标准模式”行为的好处,您需要在IE8标准模式下进行渲染。

This mode affects the rendering of your HTML+CSS as well as the fixes to JavaScript methods like document.getElementById( id ); and .setAttribute( name, value );

此模式会影响HTML + CSS的呈现以及对document.getElementById(id)等JavaScript方法的修复;和.setAttribute(name,value);

#2


You should also have a look at jQuerys jQuery.support . It will tell you what standards are supported by the browser (boxModel, opacity, etc.)

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

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

i.e.

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

#1


Before IE8:

alert('Page was rendered in ' +
  ((document.compatMode == 'CSS1Compat') ? 'Standards' : 'Quirks') + ' Mode.');

For 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);

Be aware that to gain the benifits of IE8's new "standards mode by default" behavior you'll need to be rendering in IE8 Standards Mode.

请注意,要获得IE8新的“默认标准模式”行为的好处,您需要在IE8标准模式下进行渲染。

This mode affects the rendering of your HTML+CSS as well as the fixes to JavaScript methods like document.getElementById( id ); and .setAttribute( name, value );

此模式会影响HTML + CSS的呈现以及对document.getElementById(id)等JavaScript方法的修复;和.setAttribute(name,value);

#2


You should also have a look at jQuerys jQuery.support . It will tell you what standards are supported by the browser (boxModel, opacity, etc.)

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

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

i.e.

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