在 chrome/safari 中使用滚动高度调整 iframe 大小 [英] iframe resizing with scrollheight in chrome/safari

查看:25
本文介绍了在 chrome/safari 中使用滚动高度调整 iframe 大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据 iframe 的内容调整(放大或缩小)iframe 的大小.单击每个页面后,会调用一个方法来调整大小.

I'm trying to resize (make bigger or smaller) an iframe based on it's contents. After a click on each page a method is called which does the resizing.

在 Chrome 中,我可以使 iframe 更大,但不能更小.document.body.scrollHeight 始终是最大的值.

In Chrome I can make the iframe bigger, but not smaller. document.body.scrollHeight is always the biggest value.

因此,如果一个大页面设置了#iframe.height = '620px',并且有人点击了指向内容较少的页面的链接,scrollHeight 将保持在 620px 而不是减少.

So if one big page sets #iframe.height = '620px', and someone clicks on a link to page with less content scrollHeight will remain at 620px instead of decreasing.

在 Chrome/Safari 中处理此问题的正确方法是什么?

What's the proper way of handling this in Chrome/Safari?

推荐答案

在您询问 iframe 内文档的高度之前,您应该将 iframe 对象的高度设置为自动".像这样:

Before you ask for the height of the document inside the iframe you should set the height of the iframe object to "auto". Something like this:

objIframe = document.getElementById('theIframeId');    
objIframe.style.height = 'auto';

现在:

document.body.scrollHeight

返回文档的实际高度.

这篇关于在 chrome/safari 中使用滚动高度调整 iframe 大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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