IE6/IE7 vs. IE8 give different document.documentElement.scrollHeight

Discussion in 'Javascript' started by Daniel Kabs, Apr 23, 2009.

  1. Daniel Kabs

    Daniel Kabs Guest

    Hi there,

    to make a long story short: in Internet Explorer 8, I am having problems
    getting the correct height of the HTML element.

    As you know, the HTML element is the outermost box in a document. The
    W3C has standardized document.documentElement as a shortcut to this
    element through client side Javascript. The height of the HTML element
    can be gathered from document.documentElement.scrollHeight. See MSDN for
    further reference:

    documentElement Property
    http://msdn.microsoft.com/en-us/library/ms533739(VS.85).aspx
    scrollHeight Property
    http://msdn.microsoft.com/en-us/library/ms534615(VS.85).aspx


    Now document.documentElement.scrollHeight gives different results on
    IE6/7 and IE8.



    As an example, try this short page (which is rendered in
    standards-compliant mode):

    http://www.colincochrane.com/examples/doctypes/html401-transitional.html

    Then execute the following Bookmarklet:

    javascript:alert(document.documentElement.scrollHeight);void(document.documentElement.style.border="1px
    solid green");

    It outputs the height of the HTML element (and creates a green border
    around the HTML element to make is visually prominent).

    I get the following results

    IE6: 149
    IE7: 149
    IE8: 812

    Why is this?
    How can I get a consistent reading of the height of the HTML element in
    all versions of IE?

    Thanks for any help in advance,
    Daniel
    --
    ,-. . . .
    ,-. ,-. | | ,-. /,-.\ | , ,-. |-. ,-. . ,-| ,-.
    | | |-' ||| `-. |,-|| |< ,-| | | `-. | | | |-'
    ' ' `-' `^' `-' \`-^/ ' ` `-^ ^-' `-' ' :; `-^ `-'
    `-'
     
    Daniel Kabs, Apr 23, 2009
    #1
    1. Advertising

  2. Daniel Kabs

    Eric Bednarz Guest

    Daniel Kabs <> writes:

    > http://www.colincochrane.com/examples/doctypes/html401-transitional.html
    >
    > Then execute the following Bookmarklet:


    Why wouldn’t you just use the console?

    > javascript:alert(document.documentElement.scrollHeight);void(document.documentElement.style.border="1px
    > solid green");


    […]

    > I get the following results
    >
    > IE6: 149
    > IE7: 149
    > IE8: 812


    I get 148 in ‘IE7 Standards’ mode and 160 in ‘IE8 Standards (Page
    Default)’. document.body.currentStyle.margin differs between the two
    modes, so that would explain that little difference.

    > Why is this?


    Maybe you pushed some wrong buttons in the developer toolbar, or put
    your site in the Compatibility View list without noticing.

    > How can I get a consistent reading of the height of the HTML element
    > in all versions of IE?


    In *all* of them? :)
     
    Eric Bednarz, Apr 23, 2009
    #2
    1. Advertising

  3. Daniel Kabs

    Daniel Kabs Guest

    Eric Bednarz wrote:
    >> Then execute the following Bookmarklet:

    >
    > Why wouldn’t you just use the console?


    Where is the console in IE6 and IE7?

    > I get 148 in ‘IE7 Standards’ mode and 160 in ‘IE8 Standards (Page
    > Default)’. document.body.currentStyle.margin differs between the two
    > modes, so that would explain that little difference.


    That's strange. I wonder why I get a totally different value.

    > Maybe you pushed some wrong buttons in the developer toolbar, or put
    > your site in the Compatibility View list without noticing.


    When IE8 is in Compatibility View, navigator.userAgent should contain
    the version string "MSIE 7.0". I will check this.

    I will also do my tests again with a fresh installation of XP, just to
    make sure.

    Thanks.

    Cheers
    Daniel
    --
    ,-. . . .
    ,-. ,-. | | ,-. /,-.\ | , ,-. |-. ,-. . ,-| ,-.
    | | |-' ||| `-. |,-|| |< ,-| | | `-. | | | |-'
    ' ' `-' `^' `-' \`-^/ ' ` `-^ ^-' `-' ' :; `-^ `-'
    `-'
     
    Daniel Kabs, Apr 24, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Martin
    Replies:
    0
    Views:
    79
    Martin
    Sep 1, 2004
  2. Replies:
    5
    Views:
    482
    David Mark
    Aug 11, 2007
  3. Jean-Fabrice RABAUTE
    Replies:
    0
    Views:
    102
    Jean-Fabrice RABAUTE
    Mar 20, 2008
  4. vunet
    Replies:
    1
    Views:
    150
    Felix Stahlberg
    Aug 31, 2008
  5. cecile

    ie8!=ie8

    cecile, May 24, 2010, in forum: Javascript
    Replies:
    2
    Views:
    190
    David Mark
    May 24, 2010
Loading...

Share This Page