How can I get a parent window's height from wi

2019-01-23 04:57发布

Within an iFrame, we need to get the parent's window/document height.

Is there a way to get this using jQuery?

I know we can use $(document).height() to get a page's height. I just can't figure out how to get the parent's value from within the iFrame.

Please help!

4条回答
Ridiculous、
2楼-- · 2019-01-23 05:32

I tried the clientHeight approach on a website where both Iframes where on the same domain and it didn't work. (return 0).

After a lot of testing the best way I have found (and I'll be happy to learn a better way) is to create a function on the parent which returns the document height, something like:

Parent:

function getDocumentHeight(){
   return $(document).height();
}

Iframe:

var parentDocHeight = parent.getDocumentHeight();
查看更多
ゆ 、 Hurt°
3楼-- · 2019-01-23 05:32

In jQuery you can do

$(parent.window).width();
查看更多
戒情不戒烟
4楼-- · 2019-01-23 05:33

Another possibility is :

$(window.parent.document).height()
查看更多
该账号已被封号
5楼-- · 2019-01-23 05:39

jQuery is not needed.

parent.document.body.clientHeight

That works for me with IE7 and FF3.

查看更多
登录 后发表回答