我想有一个 iframe 采取尽可能多的垂直的空间,因为它需要显示其内容并不显示一个滚动条。它是在所有可能吗?

是否有任何解决方法?

有帮助吗?

解决方案

这应该设置 IFRAME 高对其内容的高度:

<script type="text/javascript">
the_height = document.getElementById('the_iframe').contentWindow.document.body.scrollHeight;
document.getElementById('the_iframe').height = the_height;
</script>

你可能想要加入 scrolling="no" 你的 IFRAME 关闭的滚动条。

编辑: 糟糕,忘了声明 the_height.

其他提示

的解决方法不是使用 <iframe> 和处理上的代码服务器的一侧。

这CSS段应该删除垂直滚动:

body {
  overflow-x: hidden;
  overflow-y: hidden;
} 

我不确定还有它采取了垂直的空间,因为它需要,但我会看看我能不能弄清楚。

增加一个 DOCTYPE 宣言 IFRAME 来源文件将有助于计算正确的价值由线

document.getElementById('the_iframe').contentWindow.document.body.scrollHeight

看看 W3C DOCTYPE的例子

我是有问题的两即和FF因为它是渲染的 iframe 文件中'特点'模式,直到我加入了 DOCTYPE.

FF/IE/铬的支持:。scrollHeight不起作用的铬,所以我已经想出了一个javascript例如使用jQuery设置的所有 IFRAME 高地在网页基础上的内部框架的内容。注:这是供参考的网页内您当前的领域。

<script type="text/javascript">
    $(document).ready(function(){
        $('iframe').each(function(){
            var context = $(this);
            context.load(function(event){ // attach the onload event to the iframe  
                var body = $(this.contentWindow.document).find('body');
                if (body.length > 0 && $(body).find('*').length > 0) { // check if iframe has contents
                    context.height($(body.get(0)).height() + 20);
                } else {
                    context.hide(); // hide iframes with no contents
                }
            });
        });
    });
</script>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top