根据窗口大小动态定义iframe高度(NOT CONTENT) [英] Dynamically define iframe height based on window size (NOT CONTENT)

查看:116
本文介绍了根据窗口大小动态定义iframe高度(NOT CONTENT)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了一些帖子,例如如何动态调整Firefox中的iFrame大小?讨论基于远程内容调整iframe的大小;但是,我没有找到一种方法(在Firefox中)根据窗口大小设置iframe的高度。

I have found threads such as How to dynamically resize iFrame in Firefox? which talk about sizing an iframe based on the remote content; however, I have not found a way (in Firefox) to set the height of the iframe based on the window size.

其他浏览器可以使用 .body.scrollHeight 但似乎Firefox无法使用它。请参阅... http://jsfiddle.net/gjrowe/X63KR/

Other browsers are able to use .body.scrollHeight but it appears that Firefox can't use that. See... http://jsfiddle.net/gjrowe/X63KR/

要查看自动调整大小的iframe,请查看此页面... http://jsfiddle.net/gjrowe/y2WCP/

To see the iframe in action with the auto-sizing, view this page... http://jsfiddle.net/gjrowe/y2WCP/

它适用于浏览器,例如Chrome但不适用于Firefox

It works in browsers such as Chrome but not Firefox

推荐答案

以下是我为跨浏览器修复所做的事情......

Here is what I did to have a cross-browser fix...

I添加了这个javascript函数...

I added this javascript function...

function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

然后我改变了......

I then changed...

var content_height=document.body.scrollHeight-100;

to ...

var content_height=getDocHeight()-100;

你可以在 http://jsfiddle.net/y2WCP/9/

这篇关于根据窗口大小动态定义iframe高度(NOT CONTENT)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆