搜索

首页  >  问答  >  正文

javascript - 火狐获取浏览器高度

在其他浏览器都可以获取到$('html').height()//浏览器的高度,但在firefox 尝试了各种方法都不行

$('body').height() 其他网上搜索出来的原生js获取浏览器高度或者当前页面的高度都不行。 其他浏览器(Chrome,IE10)正常。

另外这个网页是在一个IFrame里头的。当然,脚本也是在Iframe里头。

PHPzPHPz2872 天前732

全部回复(2)我来回复

  • 迷茫

    迷茫2017-04-10 12:49:38

    你这里的浏览器高度指的是?看你的代码应该是用了jquery,那么iframe里

    • $(document).height()是获取iframe文档的高度
    • $(window).height()是获取iframe框的高度
    • $(window.parent.document).height()是获取外层文档的高度
    • $(window.parent.window).height()是获取外层框的高度 // 猜你可能是想要这个吧

    实测CHROME29.0.1547.65、FF23.0.1、SAFARI6.0.5有效

    回复
    0
  • 高洛峰

    高洛峰2017-04-10 12:49:38

    一般: document.body.clientHeight/document.body.clientWidth

    火狐:document.documentElement.clientWidth/document.documentElement.clientHeight

    另外你需要用css将html和body的高度设置为100%

    html,body{ height: 100%, width: 100% }

    回复
    0
  • 取消回复