Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect Render Mode of browser for current page?

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

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

like image 248
Morgan Cheng Avatar asked Mar 08 '09 04:03

Morgan Cheng


People also ask

How do I know if my browser is in quirks mode?

In Firefox and Opera you can determine if your browser is in "quirks mode" by checking page info. Using document. compatMode , will tell you the mode you are in with most browsers.

What is a rendered HTML page?

Rendering a webpage is the process of turning HTML, CSS, and JavaScript code into an interactive page that website visitors expect to see when clicking on a link. Every website page is designed with the end user in mind.


2 Answers

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.

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

like image 85
scunliffe Avatar answered Nov 06 '22 04:11

scunliffe


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

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

i.e.

jQuery.support.boxModel; //false in IE when in quirksmode, true otherwise.
like image 20
Pim Jager Avatar answered Nov 06 '22 03:11

Pim Jager