我是 HTML5 的新手,我做了一些研究,发现使用 <frameset>
已经过时,而我读到的 <iframes>
则没有过时。因此,谁能帮帮我,我想得到与示例中相同的结果,但同时使用 <iframes>
或其他在 HTLM5 中未过时的 <frameset>
替代品?
<frameset cols="20%,*,">
<frame src="menu.html">
<frame src="events.html">
</frameset>
框架已被淘汰,因为它们会给网址导航和超链接带来麻烦,因为网址只会指向索引页面(带有框架集),而且无法指定每个框架窗口中的内容。 如今,网页通常由 PHP、ASP.NET、Ruby 等服务器端技术生成。因此,网页可以不使用框架,而是通过将模板与内容合并生成,就像这样:
模板文件
<html>
<head>
<title>{insert script variable for title}</title>
</head>
<body>
<div class="menu">
{menu items inserted here by server-side scripting}
</div>
<div class="main-content">
{main content inserted here by server-side scripting}
</div>
</body>
</html>
如果您不完全支持服务器端脚本语言,也可以使用服务器端包含([SSI][1])。这样也能实现同样的功能,即从多个源文件生成一个网页。
但是,如果你真的只是想让网页的一部分成为一个单独的窗口,并在其中加载不一定位于你自己服务器上的其他网页,你就必须使用 iframe。
您可以这样模拟您的示例
框架示例
<html>
<head>
<title>Frames Test</title>
<style>
.menu {
float:left;
width:20%;
height:80%;
}
.mainContent {
float:left;
width:75%;
height:80%;
}
</style>
</head>
<body>
<iframe class="menu" src="menu.html"></iframe>
<iframe class="mainContent" src="events.html"></iframe>
</body>
</html>
可能有更好的方法来实现布局。我使用了 CSS float 属性,但你也可以使用表格或其他方法。
[1]: http://httpd.apache.org/docs/current/howto/ssi.html "SSI";
HTML 5 确实支持 iframe。还添加了一些有趣的属性,如"sandbox"和"srcdoc"。
http://www.w3schools.com/html5/tag_iframe.asp
或者您可以使用
<object data="framed.html" type="text/html"><p>This is the fallback code!</p></object>