3

I have the following structure of my website:

<html>
  <iframe>
    <iframe>
    </iframe>
  </iframe>
<html>

I am prgramming the part of the most inner iframe. Now I want to determine the available height of the browser window (starting under the menubar and ending before possible toolbars).

I have IE9 and tried somthing like:

window.innerHeight

(result undefined) and

window.parent.document.body.clientHeight 

(not the height I expected).

How do I get the height? Thanx in advance.

zuluk
  • 1,557
  • 8
  • 29
  • 49

3 Answers3

6

window.parent.document.body.clientHeight

(not the height I expected). How do I get the height? Thanx in advance.

That is because window.parent would be the iframe above it, not the top level.

You want to use window.top

epascarello
  • 204,599
  • 20
  • 195
  • 236
  • window.top.document.body.clientHeight gives me the same height as window.parent.document.body.clientHeight... and this height is too small – zuluk Aug 21 '13 at 15:05
  • well I believe you should be using innerHeight for non IE browsers – epascarello Aug 21 '13 at 15:44
  • worked perfectly for me! here is all my code: `window.parent.innerHeight` Saved me a ton of time! Thank you so much! – www139 Mar 14 '15 at 00:45
0

Also note that window.parent is a reference to the window object for the hosting document. So you can do window.parent.innerHeight (or window.top.innerHeight)

Though there is no single way of obtaining the height of the document window, cross brower. See Get the size of the screen, current web page and browser window for a quick, cross browser solution and a more detailed explanation

Community
  • 1
  • 1
Jake
  • 48
  • 6
0

I tried a bit and found the following one as the for me working solution:

top.document.getElementsByTagName("html")[0].offsetHeight
zuluk
  • 1,557
  • 8
  • 29
  • 49