最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - get available height of browser window from within iframes - Stack Overflow

programmeradmin1浏览0评论

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
发布评论

评论列表(0)

  1. 暂无评论