Great for testing/debugging: IE9’s Document Modes and JavaScript (via the IEBlog)

Internet Explorer 9 standards document mode enables the same markup and same
script to work across browsers. You should use Internet Explorer 9 standards
document mode to take advantage of new features in the
ECMAScript, Fifth Edition standard
(ES5) and IE9’s
enhanced DOM programmability
. However, to maintain fidelity with
older versions of IE, the JavaScript functionality supported in IE9’s Quirks
mode, IE7 standards mode, and IE8 standards mode differs somewhat from IE9
standards mode. You can use these compatibility modes and the F12 developer
tools to migrate your site to use the new ES5 features on your own schedule,
while your site continues to run in IE9.

In two blog posts – Testing
sites with Browser Mode vs. Doc Mode
and
IE’s Compatibility Features for Site Developers
– Marc Silbey
explains how to take advantage of document modes in Internet Explorer 9. He
also discusses how to use Browser Mode and Document Mode to test sites for
IE9 and previous IE versions. In this post, we’ll explore what developers
need to know about how the document modes in IE9 affect JavaScript code.

Document Modes and JavaScript Support

As mentioned
in a previous post
, you (the developer) control the document mode
that IE will use when rendering your site by using the DOCTYPE and
X-UA-Compatible Meta tag or HTTP Header. Chakra, the new JavaScript engine in
IE9, uses the document mode to determine the JavaScript features to support.
The table below summarizes Chakra’s JavaScript support under the four IE9
document modes. For information on how to set the document mode, see our post
on
IE’s Compatibility Features for Site Developers
and the
Determining Document Mode diagram for IE9
.

Document
Mode
Description
IE9
standards
IE9
standards document mode is the default if a Web page uses a standards-compliant
DOCTYPE and doesn’t specify an X-UA-Compatible meta tag. In this mode,
IE supports
ECMAScript, Fifth Edition features
,
enhanced DOM programmability
, and
removes
some of the key
differences
between our IE8 JavaScript
implementation and the ECMAScript, Third Edition Specification.
IE8
standards
IE8
standards document mode supports the JavaScript additions we made in IE8 to
implement portions of the then-draft ES5 standard, such as
native JSON support
and
accessor support on DOM objects
. This mode also supports
the
changes
made in IE8 to fix some key issues raised by
developers.
IE7
standards
IE7
standards document mode supports the JavaScript functionality that was available
in IE7, including the
Microsoft extensions supported in the IE7 standards mode
in
IE7 and IE8.
Quirks Quirks
mode supports the JavaScript functionality of IE6, and the Quirks mode of
IE7 and IE8.

Your JavaScript may behave differently in the different document modes.
Here are three examples of code that, due to our conformance to the ES5
standard, provide different results depending upon the document mode. For
additional compatibility guidance and JavaScript feature changes in IE9, see
the
Compatibility Cookbook on MSDN
, the blog post
Enhanced Scripting in IE9: ECMAScript 5 Support and More
, the ES3
Standards Support document
, and the
Microsoft JScript extensions to the ES3 standard
.

About TechPreacher

Software Development Engineer working for Microsoft in Switzerland. Focusing on the Internet of Things and Windows development. EV geek and passionate gamer, with a life.
%d bloggers like this: