自动调整iframe高度与内容的高度? [英] Automatically adjust iframe height to height of content?

查看:74
本文介绍了自动调整iframe高度与内容的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让iframe自动调整其高度到内容的高度,以便永远不需要滚动iframe?现在我只是指定一个非常大的高度(5000px)来容纳尽可能高的内容。


谢谢,


Don Culp

解决方案

是的。使用javascript,jQuery或其他框架之一,您可以检索您关注的内容元素的高度,然后设置iframe的高度。您将不得不使用iframe的src属性和iframe
窗口的文档对象,如果未在目标文档中明确设置相关对象的高度,事情会变得更复杂。


但是,是的,可以做到。更好的问题是为什么避免垂直滚动条很重要,这是一个标准的浏览器UI元素。


欢呼,

scott


Is there any way to have an iframe automatically adjust its height to the height of the content so that scrolling the iframe would never be needed? Right now I'm just specifying a very large height (5000px) to accommodate the highest possible content.

Thanks,

Don Culp

解决方案

Yes. Using javascript, jQuery, or one of the other frameworks you can retrieve the height of the content element you're concerned with, then set the height of the iframe. You'll have to use the src property of the iframe, and the document object of the iframe window, and things get more complicated if the height of the object in question is not explicitly set in the target document.

But, yeah, it can be done. The better question is why it is important to avoid the vertical scrollbar, which is a standard browser UI element.

cheers,
scott


这篇关于自动调整iframe高度与内容的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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