3

I would like to ask if Internet Explorer in QuirksMode has a different JavaScript implementation than IE in a normal mode (when doctype is correctly defined).

Is it possible that a JavaScript code will behave in a different way in QuirksMode and in normal IE mode?

1
  • 1
    Do you mean Javascript code itself or the HTML DOM, these are often incorrectly confused? Oct 1, 2009 at 13:17

3 Answers 3

10

Yep.

One of the most noticeable differences is that in quirks mode, BODY (document.body) is considered to be root element, whereas in standard mode (and the way it's meant to be) - root element is HTML (document.documentElement).

This, for example, affects the way viewport dimensions are usually calculated; in standard mode, one would use document.documentElement.clientHeight, while in quirks - document.body.clientHeight - to get height of a viewport.

Detecting this behavior is easy - document.documentElement.clientHeight == 0 - would tell us that documentElement is not the root element, and that body should be used instead.

And of course other usual quirks mode discrepancies, such as assigning unitless CSS values, result in a different outcome. When in quirks, such values are traditionally assigned successfully, whereas in standards mode - they are ignored.

2
  • 3
    It's probably worth pointing out that these are differences in the Document Object Model. The JavaScript implementation remains identical whether in quirks mode, strict mode, or being used in some non-browser context.
    – NickFitz
    Oct 1, 2009 at 18:22
  • @NickFlitz Yes, of course. It would be weird if quirks mode affected core language implementation :) (although with IE - you never know...)
    – kangax
    Oct 1, 2009 at 18:59
6

JavaScript should not behave differently; however, the DOM objects that JavaScript operates on may have different behaviors.

3

It certainly does in Internet Explorer 8 where full standards mode no longer gets <a name="foo"> when asked document.getElementById('foo') and where (IIRC) setAttribute and friends are fixed.

1
  • 3
    That's a DOM difference, not a JavaScript difference.
    – NickFitz
    Oct 1, 2009 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.