我在 HTML 页面中有大量内容,我想将其放入 iframe 中。但是将内容放在页面内的 iframe 标记中,页面显示该部分为空白。请建议我们如何将内容放在同一个 HTML 的 iframe 中。如果应用相同的页面内容,应该在src中放置什么。
<iframe src="">
//Content
</iframe>
谢谢。
最佳答案
我强烈建议,如果您想将当前页面的大部分输出放入页面的可滚动区域,请不要使用 iframe,而应执行以下操作:
<div style="overflow-y: auto; width: 100%; height: 400px;">
<!-- put all of your large amount of content after this comment, before the closing div tag -->
<p>this is my huge amount of content (just an example.... you'd have hundreds of lines of code here I suspect</p>
</div>
当然,您可以根据需要更改 div 的高度和宽度。
div style="overflow-y: auto;"具有指定的宽度和高度应该(我认为)在您的页面中创建一个类似于 iframe 输出的可滚动区域,但不需要浏览器加载内容的两个副本。您还可以避免无限循环的可能性。
如果您愿意,您还可以在该区域周围添加边框,例如在 height: 400px 之后;通过将第一行更改为:
<div style="overflow-y: auto; width: 100%; height: 400px; border: 2px solid grey;">
关于javascript - 页面内容中的 HTML Iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22767723/