我知道现代浏览器通常有两种渲染模式:标准模式和怪异模式。浏览器会检测文档类型标头。
问题是如何在运行时检测当前页面的渲染模式。是否有任何 Firebug 工具来完成这个任务?
问题是如何在运行时检测当前页面的渲染模式。是否有任何 Firebug 工具来完成这个任务?
在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的呈现以及JavaScript修复方法,例如document.getElementById(id);
和.setAttribute(name, value);
http://docs.jquery.com/Utilities/jQuery.support
即
jQuery.support.boxModel; //false in IE when in quirksmode, true otherwise.
_javascript:(function(){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);})();_
如果您使用此代码创建了收藏夹,可以将其命名为“检测呈现模式”。只需单击即可获取消息框。 - SimonSimCitydocument.compatMode
来判断它是BackCompat
(怪异模式)还是CSS1Compat
(标准兼容模式)呢? - nonopolarity