1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

how to get the page height (not window height) with javaScript

Discussion in 'JavaScript' started by nandoP, Nov 4, 2009.

  1. #1
    I've been trying to get the document's height (i.e. the total height including the part that is not visible) and only get the window height
    theses are some of the results I've got:
    var y = document.documentElement.clientHeight;/*window height*/
    var z = document.documentElement.scrollHeight; /*window height*/
    var a =document.documentElement.offsetHeight; /*0 in FF - window height in IE*/
    var b= document.documentElement.scrollTop;/*0 in FF - 0 IE*/
    var c= document.documentElement.scrollTop;/*0 in FF - 0 IE*/

    I've searched in google for hours without any luck

    Any help will be much appreciated
    nandoP, Nov 4, 2009 IP
  2. mastermunj

    mastermunj Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    35
  3. nandoP

    nandoP Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    nandoP, Nov 5, 2009 IP
  4. FilmFiddler

    FilmFiddler Greenhorn

    Messages:
    54
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    23
    #4
    I find that 'document.documentElement.scrollHeight' is actually a reliable getter of the full rendered page height. It never seemed to get confused with the window height in any of the browsers I tested, using a strict html doctype.

    Out of curiosity, I also tried using 'document.body.scrollHeight'. That failed only in Firefox (v3.5), which returned the window height.
    FilmFiddler, Nov 8, 2009 IP
  5. nandoP

    nandoP Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I've used: 'document.documentElement.scrollHeight and get the window height both in FF and IE6, with a difference of about 20px
    nandoP, Nov 16, 2009 IP
  6. FilmFiddler

    FilmFiddler Greenhorn

    Messages:
    54
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    23
    #6
    Just wondering if your actual page content is small and occupies less than the window height. In that case, yes - the scrollHeight will return the window height as a minimum; it won't return anything less than the window height.

    If you want to measure the height of such small page content, you might need to put it in a div wrapper and get the offsetHeight of the wrapper.
    FilmFiddler, Nov 19, 2009 IP
    jonix likes this.
  7. jonix

    jonix Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    tnx FilmFiddler! I spent several hours on this issue and then I found this your post. It works! Thank you very much!
    jonix, Nov 26, 2011 IP