IE8 - Yes Compat Mode is Supposed to Do That

If you do any work with IE8 at all you are surely familiar with its various compatibility modes.  Basically the browser will flip into quirks mode or strict mode depending on the doctype and you can of course force the issue with tags or HTTP headers.  Now generally when people discuss these modes it tends to be focused on the markup and CSS quirks that plague that browser.  Well dear readers, that just scratches the surface it would appear.

Consider a nice feature in IE8, the inclusion of native JSON parsing.  If you are dealing with any mass of JSON data returned via Ajax parsing natively is a speed godsend.  Most libraries like jquery try to get advantage of browser native JSON using detection to see if it can be used or if we should rely on a rolled version.   To safely use such features you likely might use a little object detection.  Here for example, is a simple test to see if JSON might be around to use.

var nativeJSON;
nativeJSON = window.JSON ? true : false;

var nativeJSON;
nativeJSON = window.JSON ? true : false;
document.write("Native JSON Support: "+nativeJSON);

In the normal strict mode assuming you have a doctype properly set, the browser will display that indeed IE8 supports native JSON.

JSON is available in IE8 by defaultJSON is available in IE8 by default

Of course if for some reason you find yourself in compat mode either by button press – you know that broken document button or because someone is monkeying with the doctype to see if they can coax IE into rendering some old layout right, well then you might be in trouble. You see in compat mode you aren’t just changing markup compatibility, you are changing scripting too! So bye bye native JSON, hello potential scripting errors.

Scripting features may be disabled in compat modeScripting features may be disabled in compat mode

IE8 Conclusions and Takeaways

So the morale of the story – when Microsoft says IE is emulating another version assume they don’t just mean markup they mean everything!

Oh interestingly we have seen some more havoc that gets played as IE  compat modes.  The browser will actually send other user-agent headers when you flip modes.  This makes perfect sense it should, you see you are trying to emulate.  However, it turns out you can be quite mischievous with such a feature and maybe inadvertently. Really strong Web security systems may bind your user-agent with your cookie and if you start flipping in and out of one user-agent string and another during a session you are going to potentially flag yourself or just get plain booted.  For extra credit try doing such things on your bank site and see if they like it!

Related Articles

Your Tags are Slowing You Down

Tags are an important way to track analytics on your site, but they may be increasing your load time. ...

Jun 28th / By Nate Weintraub

The Benefits of Installing SSL

Installing an SSL Certificate on your website provides a myriad of benefits including keeping modern browsers from telling your users your site is insecure. ...

Jun 22nd / By Julian Dutton

Tell us about your project

Please fill out your information and submit