禁用 iframe 自动调整大小
我正在使用一个包含 iframe 的网页。 iframe 中包含大量数据,每次加载时,其高度都会扩展到其中内容的范围。然而,这使我的页面消失了。是否有办法锁定 iframe 的高度并允许用户滚动浏览内容?
I am working with a webpage with an iframe within it. The iframe has a fair amount of data in it and every-time it loads its height expands to the extent of the content within. However this puts my page out. Is there anyway to lock the height of the iframe and allow the user too scroll through the content??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
嗯,奇怪......你有这个问题的示例链接吗?
当我尝试一个简单的 iframe 时:
http://jsfiddle.net/mP6wT/5/
默认情况下它的尺寸似乎很小,并在 Chrome/FF/Win 中滚动...而不是调整高度...
但无论如何,您应该能够使用 CSS 锁定高度:
http://jsfiddle.net/mP6wT/7/
Hmm, weird... do you have an example link of this issue?
When I try a simple iframe:
http://jsfiddle.net/mP6wT/5/
It seems to be sized pretty small by default, and scrolls in Chrome/FF/Win... Rather than adjusting to the height...
But at any rate, you should be able to lock the height with CSS:
http://jsfiddle.net/mP6wT/7/
留意 iOS。它有点搞砸了一切:
http://salomvary.github.io/iframe-调整大小-ios-safari.html
如何在移动 Safari 中正确显示 iFrame
Watch out for iOS. Its kinda screws everything up:
http://salomvary.github.io/iframe-resize-ios-safari.html
how to properly display an iFrame in mobile safari
给 iframe 一个固定的高度并自动滚动,你应该就可以了。
请注意,100px 只是一个示例,您可能需要选择适合您的高度。
Give the iframe a fixed height and scroll auto and you should be good.
Note that 100px is just an example, you might want to choose a height that suits you.
您的 iframe 可能已设置
height: 100%;
,甚至高度是通过某种脚本设置的。从技术上讲,您可以设置高度或
= 高度 300 像素。
由于您没有提供任何代码,我无法进一步帮助您:(提供您的实时示例或代码,然后我们可以更好地帮助您。但一般来说,要么尝试手动设置 iframe 高度,然后重新检查您的页面代码..也许某些脚本正在设置高度,或者可能是 iframe 内的代码。
Your iframe probably has
height: 100%;
set or even the height is being set via script of some sort. Technically you can set the height<iframe height="300"></iframe>
or<ifreame style="height: 300px;"></iframe>
= height of 300px.Since you didn't provide any code, I cannot help you any further :( Provide your live example or code, then we can help you better. But generally, either try manually setting the iframes height, re-check your pages code.. maybe some script is setting the height or maybe the code inside the iframe..