【问题标题】:HTML Iframe within page content页面内容中的 HTML Iframe
【发布时间】:2014-05-11 03:43:15
【问题描述】:
我在 HTML 页面中有大量内容,我想将其放入 iframe 中。但是将内容放在页面内的 iframe 标记中,页面将该部分显示为空白。请建议我们如何将 iframe 中的内容放在同一个 HTML 中。如果应用相同的页面内容,应该在 src 中放置什么。
<iframe src="">
//Content
</iframe>
谢谢。
【问题讨论】:
标签:
javascript
php
html
css
user-interface
【解决方案1】:
我强烈建议,如果您想将当前页面的大部分输出放入页面的可滚动区域,请不要使用 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;">
【解决方案2】:
你可以把链接放到你需要显示内容的页面
<iframe src="http://www.yoursite.com"></iframe>
src = 可能被空格包围的 URL 给出页面的地址
嵌套浏览上下文要包含的内容。
阅读iframes
【解决方案3】:
例如,你所有的 HTML 都在 index.html 中,只需将 src 属性设置为 index.html。
像这样:
<iframe src="index.html"></iframe>
请记住,这不一定能正常工作,因为您会将<iframe> 运行到一个连续循环中。不过,如果我错了,请纠正我,它只会将 iframe 重复两次作为安全策略。
【解决方案4】:
<iframe src="URL or pagename.html"></iframe>