admin管理员组

文章数量:1388153

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.

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.

Share Improve this question edited Aug 21, 2013 at 15:29 zuluk asked Aug 21, 2013 at 14:56 zulukzuluk 1,5778 gold badges30 silver badges53 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 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

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

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

top.document.getElementsByTagName("html")[0].offsetHeight

本文标签: javascriptget available height of browser window from within iframesStack Overflow